fix(test runner): correctly save videos when running remotely (#11633)

This commit is contained in:
Dmitry Gozman 2022-01-26 07:43:07 -08:00 committed by GitHub
parent 6b21400468
commit 19820de7a9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 2 deletions

View File

@ -392,6 +392,7 @@ export const test = _baseTest.extend<TestFixtures, WorkerFixtures>({
const prependToError = testInfo.status === 'timedOut' ?
formatPendingCalls((browser as any)._connection.pendingProtocolCalls()) : '';
let counter = 0;
await Promise.all([...contexts.keys()].map(async context => {
await context.close();
@ -402,8 +403,8 @@ export const test = _baseTest.extend<TestFixtures, WorkerFixtures>({
const videos = pages.map(p => p.video()).filter(Boolean) as Video[];
await Promise.all(videos.map(async v => {
try {
const videoPath = await v.path();
const savedPath = testInfo.outputPath(path.basename(videoPath));
const savedPath = testInfo.outputPath(`video${counter ? '-' + counter : ''}.webm`);
++counter;
await v.saveAs(savedPath);
testInfo.attachments.push({ name: 'video', path: savedPath, contentType: 'video/webm' });
} catch (e) {

View File

@ -492,3 +492,29 @@ test('should work with video size', async ({ runInlineTest }, testInfo) => {
expect(videoPlayer.videoWidth).toBe(220);
expect(videoPlayer.videoHeight).toBe(110);
});
test('should work with video.path() throwing', async ({ runInlineTest }, testInfo) => {
// When running remotely, video.path() is not available, so we must not use it.
const result = await runInlineTest({
'playwright.config.js': `
module.exports = {
use: { video: { mode: 'on' } },
name: 'chromium',
preserveOutput: 'always',
};
`,
'a.test.ts': `
const { test } = pwt;
test('pass', async ({ page }) => {
page.video().path = () => { throw new Error('No-no!'); };
await page.setContent('<div>PASS</div>');
await page.waitForTimeout(3000);
});
`,
}, { workers: 1 });
expect(result.exitCode).toBe(0);
expect(result.passed).toBe(1);
const dir = testInfo.outputPath(`test-results/a-pass-chromium/`);
const video = fs.readdirSync(dir).find(file => file.endsWith('webm'));
expect(video).toBeTruthy();
});