mirror of
https://github.com/microsoft/playwright.git
synced 2025-06-26 21:40:17 +00:00
test(screencast): add auto scale test (#3733)
This commit is contained in:
parent
be5eba0cd8
commit
a588840d99
43
test/assets/checkerboard.html
Normal file
43
test/assets/checkerboard.html
Normal file
@ -0,0 +1,43 @@
|
||||
<html>
|
||||
<script>
|
||||
function changeBackground() {
|
||||
const color = location.hash.substr(1);
|
||||
document.body.style.backgroundColor = color;
|
||||
}
|
||||
</script>
|
||||
<style>
|
||||
body {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.container {
|
||||
display: grid;
|
||||
background-color: rgb(0, 0, 0);
|
||||
grid-template-columns: auto auto;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
.cell {
|
||||
border: none;
|
||||
font-size: 30px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.cell.grey {
|
||||
background-color: rgb(100, 100, 100);
|
||||
}
|
||||
|
||||
.cell.red {
|
||||
background-color: rgb(255, 0, 0);
|
||||
}
|
||||
</style>
|
||||
<body>
|
||||
<div class="container">
|
||||
<div class="cell red"></div>
|
||||
<div class="cell grey"></div>
|
||||
<div class="cell grey"></div>
|
||||
<div class="cell red"></div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
@ -41,8 +41,11 @@ async function countFrames() {
|
||||
return count;
|
||||
}
|
||||
|
||||
async function seekLastFrame() {
|
||||
const frameCount = await countFrames();
|
||||
async function seekLastFrame(isWPE) {
|
||||
let frameCount = await countFrames();
|
||||
// TODO: figure out why playing last frame in WPE resets the picture.
|
||||
if (isWPE && frameCount > 1)
|
||||
--frameCount;
|
||||
await playNFrames(frameCount);
|
||||
return frameCount;
|
||||
}
|
||||
|
||||
@ -141,7 +141,8 @@ class VideoPlayer {
|
||||
}
|
||||
|
||||
async seekLastFrame() {
|
||||
return await this._page.evaluate(async () => await (window as any).seekLastFrame());
|
||||
const isWPE = LINUX && options.WEBKIT && options.HEADLESS;
|
||||
return await this._page.evaluate(async x => await (window as any).seekLastFrame(x), isWPE);
|
||||
}
|
||||
|
||||
async pixels(point = {x: 0, y: 0}) {
|
||||
@ -312,4 +313,47 @@ describe('screencast', suite => {
|
||||
expect(path.dirname(await screencast.path())).toBe(tmpDir);
|
||||
await context.close();
|
||||
});
|
||||
|
||||
it('should scale frames down to the requested size ', test => {
|
||||
test.fixme(options.CHROMIUM && options.HEADLESS, 'Window is not resized when changing viewport');
|
||||
}, async ({page, videoPlayer, tmpDir, server, toImpl}) => {
|
||||
// Set size to 1/2 of the viewport.
|
||||
await page.setViewportSize({width: 640, height: 480});
|
||||
const videoFile = path.join(tmpDir, 'v.webm');
|
||||
await page.goto(server.PREFIX + '/checkerboard.html');
|
||||
await toImpl(page)._delegate.startScreencast({outputFile: videoFile, width: 320, height: 240});
|
||||
// Update the picture to ensure enough frames are generated.
|
||||
await page.$eval('.container', container => {
|
||||
container.firstElementChild.classList.remove('red');
|
||||
});
|
||||
await new Promise(r => setTimeout(r, 300));
|
||||
await page.$eval('.container', container => {
|
||||
container.firstElementChild.classList.add('red');
|
||||
});
|
||||
await new Promise(r => setTimeout(r, 300));
|
||||
await toImpl(page)._delegate.stopScreencast();
|
||||
expect(fs.existsSync(videoFile)).toBe(true);
|
||||
|
||||
await videoPlayer.load(videoFile);
|
||||
const duration = await videoPlayer.duration();
|
||||
expect(duration).toBeGreaterThan(0);
|
||||
|
||||
await videoPlayer.seekLastFrame();
|
||||
{
|
||||
const pixels = await videoPlayer.pixels({x: 0, y: 0});
|
||||
expectAll(pixels, almostRed);
|
||||
}
|
||||
{
|
||||
const pixels = await videoPlayer.pixels({x: 300, y: 0});
|
||||
expectAll(pixels, almostGrey);
|
||||
}
|
||||
{
|
||||
const pixels = await videoPlayer.pixels({x: 0, y: 200});
|
||||
expectAll(pixels, almostGrey);
|
||||
}
|
||||
{
|
||||
const pixels = await videoPlayer.pixels({x: 300, y: 200});
|
||||
expectAll(pixels, almostRed);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user