Skip to content

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.

feat(report): add video to attachments (#7976)

Dmitry Gozmanea4f42b7ed51
diff --git a/src/test/index.ts b/src/test/index.ts
index e963939224..075a70f5cd 100644
--- a/src/test/index.ts
+++ b/src/test/index.ts
@@ -251,8 +251,9 @@ export const test = _baseTest.extend<PlaywrightTestArgs & PlaywrightTestOptions,
return;
try {
const videoPath = await v.path();
- const fileName = path.basename(videoPath);
- await v.saveAs(testInfo.outputPath(fileName));
+ const savedPath = testInfo.outputPath(path.basename(videoPath));
+ await v.saveAs(savedPath);
+ testInfo.attachments.push({ name: 'video', path: savedPath, contentType: 'video/webm' });
} catch (e) {
// Silent catch empty videos.
}
diff --git a/tests/playwright-test/playwright.spec.ts b/tests/playwright-test/playwright.spec.ts
index 1d51af04e8..c4f009325f 100644
--- a/tests/playwright-test/playwright.spec.ts
+++ b/tests/playwright-test/playwright.spec.ts
@@ -301,8 +301,16 @@ test('should work with video: on-first-retry', async ({ runInlineTest }, testInf
const dirFail = testInfo.outputPath('test-results', 'a-fail-chromium');
expect(fs.existsSync(dirFail)).toBeFalsy();
- const videoFailRetry = fs.readdirSync(testInfo.outputPath('test-results', 'a-fail-chromium-retry1')).find(file => file.endsWith('webm'));
+ const dirRetry = testInfo.outputPath('test-results', 'a-fail-chromium-retry1');
+ const videoFailRetry = fs.readdirSync(dirRetry).find(file => file.endsWith('webm'));
expect(videoFailRetry).toBeTruthy();
+
+ expect(result.report.suites[0].specs[1].tests[0].results[0].attachments).toEqual([]);
+ expect(result.report.suites[0].specs[1].tests[0].results[1].attachments).toEqual([{
+ name: 'video',
+ contentType: 'video/webm',
+ path: path.join(dirRetry, videoFailRetry),
+ }]);
});
test('should work with video size', async ({ runInlineTest }, testInfo) => {