mirror of
https://github.com/microsoft/playwright.git
synced 2024-12-13 17:14:02 +03:00
fix(test runner): correctly save videos when running remotely (#11633)
This commit is contained in:
parent
6b21400468
commit
19820de7a9
@ -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) {
|
||||
|
@ -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();
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user