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
fix(test runner): correctly save videos when running remotely (#11633)
Dmitry Gozman19820de7a9b0
diff --git a/packages/playwright-test/src/index.ts b/packages/playwright-test/src/index.tsindex 3374aa3d72..d8b59cce66 100644--- a/packages/playwright-test/src/index.ts+++ b/packages/playwright-test/src/index.ts@@ -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) {diff --git a/tests/playwright-test/playwright.spec.ts b/tests/playwright-test/playwright.spec.tsindex 80976b98e0..cf7cb03a30 100644--- a/tests/playwright-test/playwright.spec.ts+++ b/tests/playwright-test/playwright.spec.ts@@ -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();+});