test(screencast): always use chromium to replay the video (#3841)

This commit is contained in:
Yury Semikhatsky 2020-09-10 18:09:17 -07:00 committed by GitHub
parent 2f2ca8f77a
commit d2771ebfea
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 33 additions and 46 deletions

View file

@ -22,30 +22,31 @@ async function playNFrames(n) {
await playOneFrame(); await playOneFrame();
} }
let _frameCount = -1;
async function countFrames() { async function countFrames() {
const video = document.querySelector('video'); if (_frameCount === -1) {
const video = document.querySelector('video');
if (!video.duration) if (!video.duration)
return 0; return 0;
if (video.currentTime) if (video.currentTime)
await playToTheEnd(); await playToTheEnd();
let count = 0; let count = 0;
while (true) { while (true) {
++count; ++count;
await playOneFrame(); await playOneFrame();
if (video.ended) if (video.ended)
break; break;
}
_frameCount = count;
} }
return count; return _frameCount;
} }
async function seekLastFrame(isWPE) { async function seekLastFrame() {
let frameCount = await countFrames(); let frameCount = await countFrames();
// TODO: figure out why playing last frame in WPE resets the picture.
if (isWPE && frameCount > 1)
--frameCount;
await playNFrames(frameCount); await playNFrames(frameCount);
return frameCount; return frameCount;
} }

View file

@ -29,12 +29,11 @@ declare global {
} }
registerFixture('videoPlayer', async ({playwright, context, server}, test) => { registerFixture('videoPlayer', async ({playwright, context, server}, test) => {
let chromium; // WebKit on Mac & Windows cannot replay webm/vp8 video, is unrelyable
if (options.WEBKIT && !LINUX) { // on Linux (times out) and in Firefox, so we always launch chromium for
// WebKit on Mac & Windows cannot replay webm/vp8 video, so we launch chromium. // playback.
chromium = await playwright.chromium.launch(); const chromium = await playwright.chromium.launch();
context = await chromium.newContext(); context = await chromium.newContext();
}
const page = await context.newPage(); const page = await context.newPage();
const player = new VideoPlayer(page, server); const player = new VideoPlayer(page, server);
@ -140,8 +139,7 @@ class VideoPlayer {
} }
async seekLastFrame() { async seekLastFrame() {
const isWPE = LINUX && options.WEBKIT && options.HEADLESS; return await this._page.evaluate(async x => await (window as any).seekLastFrame());
return await this._page.evaluate(async x => await (window as any).seekLastFrame(x), isWPE);
} }
async pixels(point = {x: 0, y: 0}) { async pixels(point = {x: 0, y: 0}) {
@ -162,13 +160,9 @@ class VideoPlayer {
describe('screencast', suite => { describe('screencast', suite => {
suite.slow(); suite.slow();
suite.flaky();
suite.skip(options.WIRE); suite.skip(options.WIRE);
}, () => { }, () => {
it('should capture static page', test => { it('should capture static page', async ({page, tmpDir, videoPlayer, toImpl}) => {
test.flaky(options.CHROMIUM && LINUX && !options.HEADLESS);
test.flaky(options.WEBKIT && LINUX);
}, async ({page, tmpDir, videoPlayer, toImpl}) => {
const videoFile = path.join(tmpDir, 'v.webm'); const videoFile = path.join(tmpDir, 'v.webm');
await page.evaluate(() => document.body.style.backgroundColor = 'red'); await page.evaluate(() => document.body.style.backgroundColor = 'red');
await toImpl(page)._delegate.startScreencast({outputFile: videoFile, width: 320, height: 240}); await toImpl(page)._delegate.startScreencast({outputFile: videoFile, width: 320, height: 240});
@ -189,10 +183,7 @@ describe('screencast', suite => {
}); });
it('should capture navigation', test => { it('should capture navigation', test => {
test.flaky(options.CHROMIUM && MAC); test.flaky();
test.flaky(options.FIREFOX);
test.flaky(options.WEBKIT);
test.fixme(options.WEBKIT && LINUX, 'Times out on bots');
}, async ({page, tmpDir, server, videoPlayer, toImpl}) => { }, async ({page, tmpDir, server, videoPlayer, toImpl}) => {
const videoFile = path.join(tmpDir, 'v.webm'); const videoFile = path.join(tmpDir, 'v.webm');
await page.goto(server.PREFIX + '/background-color.html#rgb(0,0,0)'); await page.goto(server.PREFIX + '/background-color.html#rgb(0,0,0)');
@ -221,7 +212,6 @@ describe('screencast', suite => {
}); });
it('should capture css transformation', test => { it('should capture css transformation', test => {
test.fixme(options.WEBKIT && LINUX, 'Times out on bots');
test.fail(options.WEBKIT && WIN, 'Does not work on WebKit Windows'); test.fail(options.WEBKIT && WIN, 'Does not work on WebKit Windows');
}, async ({page, tmpDir, server, videoPlayer, toImpl}) => { }, async ({page, tmpDir, server, videoPlayer, toImpl}) => {
const videoFile = path.join(tmpDir, 'v.webm'); const videoFile = path.join(tmpDir, 'v.webm');
@ -244,10 +234,8 @@ describe('screencast', suite => {
} }
}); });
it('should automatically start/finish when new page is created/closed', test => { it('should automatically start/finish when new page is created/closed', async ({browserType, defaultBrowserOptions, tmpDir}) => {
test.flaky(options.FIREFOX, 'Even slow is not slow enough'); const browser = await browserType.launch({ ...defaultBrowserOptions, _videosPath: tmpDir });
}, async ({browserType, tmpDir}) => {
const browser = await browserType.launch({_videosPath: tmpDir});
const context = await browser.newContext({_recordVideos: {width: 320, height: 240}}); const context = await browser.newContext({_recordVideos: {width: 320, height: 240}});
const [screencast, newPage] = await Promise.all([ const [screencast, newPage] = await Promise.all([
new Promise<any>(r => context.on('page', page => page.on('_videostarted', r))), new Promise<any>(r => context.on('page', page => page.on('_videostarted', r))),
@ -263,8 +251,8 @@ describe('screencast', suite => {
await browser.close(); await browser.close();
}); });
it('should finish when contex closes', async ({browserType, tmpDir}) => { it('should finish when contex closes', async ({browserType, defaultBrowserOptions, tmpDir}) => {
const browser = await browserType.launch({_videosPath: tmpDir}); const browser = await browserType.launch({ ...defaultBrowserOptions, _videosPath: tmpDir });
const context = await browser.newContext({_recordVideos: {width: 320, height: 240}}); const context = await browser.newContext({_recordVideos: {width: 320, height: 240}});
const [video] = await Promise.all([ const [video] = await Promise.all([
@ -281,7 +269,7 @@ describe('screencast', suite => {
await browser.close(); await browser.close();
}); });
it('should fire striclty after context.newPage', async ({browser, tmpDir}) => { it('should fire striclty after context.newPage', async ({browser}) => {
const context = await browser.newContext({_recordVideos: {width: 320, height: 240}}); const context = await browser.newContext({_recordVideos: {width: 320, height: 240}});
const page = await context.newPage(); const page = await context.newPage();
// Should not hang. // Should not hang.
@ -289,8 +277,8 @@ describe('screencast', suite => {
await context.close(); await context.close();
}); });
it('should fire start event for popups', async ({browserType, tmpDir, server}) => { it('should fire start event for popups', async ({browserType, defaultBrowserOptions, tmpDir, server}) => {
const browser = await browserType.launch({_videosPath: tmpDir}); const browser = await browserType.launch({ ...defaultBrowserOptions, _videosPath: tmpDir });
const context = await browser.newContext({_recordVideos: {width: 320, height: 240}}); const context = await browser.newContext({_recordVideos: {width: 320, height: 240}});
const [page] = await Promise.all([ const [page] = await Promise.all([
@ -312,9 +300,7 @@ describe('screencast', suite => {
await browser.close(); await browser.close();
}); });
it('should scale frames down to the requested size ', test => { it('should scale frames down to the requested size ', async ({page, videoPlayer, tmpDir, server, toImpl}) => {
test.fixme(options.WEBKIT && LINUX, 'Times out on bots');
}, async ({page, videoPlayer, tmpDir, server, toImpl}) => {
await page.setViewportSize({width: 640, height: 480}); await page.setViewportSize({width: 640, height: 480});
const videoFile = path.join(tmpDir, 'v.webm'); const videoFile = path.join(tmpDir, 'v.webm');
await page.goto(server.PREFIX + '/checkerboard.html'); await page.goto(server.PREFIX + '/checkerboard.html');