mirror of
https://github.com/microsoft/playwright.git
synced 2025-06-26 21:40:17 +00: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' ?
|
const prependToError = testInfo.status === 'timedOut' ?
|
||||||
formatPendingCalls((browser as any)._connection.pendingProtocolCalls()) : '';
|
formatPendingCalls((browser as any)._connection.pendingProtocolCalls()) : '';
|
||||||
|
|
||||||
|
let counter = 0;
|
||||||
await Promise.all([...contexts.keys()].map(async context => {
|
await Promise.all([...contexts.keys()].map(async context => {
|
||||||
await context.close();
|
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[];
|
const videos = pages.map(p => p.video()).filter(Boolean) as Video[];
|
||||||
await Promise.all(videos.map(async v => {
|
await Promise.all(videos.map(async v => {
|
||||||
try {
|
try {
|
||||||
const videoPath = await v.path();
|
const savedPath = testInfo.outputPath(`video${counter ? '-' + counter : ''}.webm`);
|
||||||
const savedPath = testInfo.outputPath(path.basename(videoPath));
|
++counter;
|
||||||
await v.saveAs(savedPath);
|
await v.saveAs(savedPath);
|
||||||
testInfo.attachments.push({ name: 'video', path: savedPath, contentType: 'video/webm' });
|
testInfo.attachments.push({ name: 'video', path: savedPath, contentType: 'video/webm' });
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|||||||
@ -492,3 +492,29 @@ test('should work with video size', async ({ runInlineTest }, testInfo) => {
|
|||||||
expect(videoPlayer.videoWidth).toBe(220);
|
expect(videoPlayer.videoWidth).toBe(220);
|
||||||
expect(videoPlayer.videoHeight).toBe(110);
|
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…
x
Reference in New Issue
Block a user