Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
TypeScript automationchromechromiume2e-testingelectronend-to-end-testingfirefoxjavascriptplaywrighttesttest-automationtestingtesting-toolswebwebkit
test(screencast): add auto scale test (#3733)
Yury Semikhatskya588840d9973
diff --git a/test/assets/checkerboard.html b/test/assets/checkerboard.htmlnew file mode 100644index 0000000000..dd21fcc530--- /dev/null+++ b/test/assets/checkerboard.html@@ -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>\ No newline at end of filediff --git a/test/assets/player.html b/test/assets/player.htmlindex 7fba69468b..ff74022bf7 100644--- a/test/assets/player.html+++ b/test/assets/player.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;}diff --git a/test/screencast.spec.ts b/test/screencast.spec.tsindex 196658bb7c..6f3fb07ee0 100644--- a/test/screencast.spec.ts+++ b/test/screencast.spec.ts@@ -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);+ }+ });});