2021-06-09 01:52:08 +03:00
|
|
|
/**
|
|
|
|
* Copyright (c) Microsoft Corporation.
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2022-02-01 04:14:59 +03:00
|
|
|
import { test, expect, stripAnsi } from './playwright-test-fixtures';
|
2021-06-16 17:51:54 +03:00
|
|
|
import fs from 'fs';
|
|
|
|
import path from 'path';
|
|
|
|
import { spawnSync } from 'child_process';
|
2022-04-07 08:21:27 +03:00
|
|
|
import { registry } from '../../packages/playwright-core/lib/server';
|
2021-06-16 17:51:54 +03:00
|
|
|
|
2021-07-14 05:03:49 +03:00
|
|
|
const ffmpeg = registry.findExecutable('ffmpeg')!.executablePath();
|
2021-06-16 17:51:54 +03:00
|
|
|
|
|
|
|
export class VideoPlayer {
|
|
|
|
videoWidth: number;
|
|
|
|
videoHeight: number;
|
|
|
|
|
|
|
|
constructor(fileName: string) {
|
2021-06-23 12:08:35 +03:00
|
|
|
const output = spawnSync(ffmpeg, ['-i', fileName, '-r', '25', `${fileName}-%03d.png`]).stderr.toString();
|
2021-06-16 17:51:54 +03:00
|
|
|
const lines = output.split('\n');
|
|
|
|
const streamLine = lines.find(l => l.trim().startsWith('Stream #0:0'));
|
2022-06-20 23:37:31 +03:00
|
|
|
const resolutionMatch = streamLine!.match(/, (\d+)x(\d+),/);
|
2021-06-16 17:51:54 +03:00
|
|
|
this.videoWidth = parseInt(resolutionMatch![1], 10);
|
|
|
|
this.videoHeight = parseInt(resolutionMatch![2], 10);
|
|
|
|
}
|
|
|
|
}
|
2021-06-09 01:52:08 +03:00
|
|
|
|
|
|
|
test('should respect viewport option', async ({ runInlineTest }) => {
|
|
|
|
const result = await runInlineTest({
|
|
|
|
'playwright.config.ts': `
|
|
|
|
module.exports = { use: { viewport: { width: 800, height: 800 } } };
|
|
|
|
`,
|
|
|
|
'a.test.ts': `
|
|
|
|
const { test } = pwt;
|
|
|
|
test('pass', async ({ page }) => {
|
|
|
|
expect(page.viewportSize()).toEqual({ width: 800, height: 800 });
|
|
|
|
});
|
|
|
|
`,
|
|
|
|
'b.test.ts': `
|
|
|
|
const { test } = pwt;
|
|
|
|
test.use({ viewport: { width: 600, height: 600 } });
|
|
|
|
test('pass', async ({ page }) => {
|
|
|
|
expect(page.viewportSize()).toEqual({ width: 600, height: 600 });
|
|
|
|
});
|
|
|
|
`,
|
|
|
|
}, { workers: 1 });
|
|
|
|
|
|
|
|
expect(result.exitCode).toBe(0);
|
|
|
|
expect(result.passed).toBe(2);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('should run in three browsers with --browser', async ({ runInlineTest }) => {
|
|
|
|
const result = await runInlineTest({
|
|
|
|
'playwright.config.ts': `
|
|
|
|
module.exports = { use: { viewport: { width: 800, height: 800 } } };
|
|
|
|
`,
|
|
|
|
'a.test.ts': `
|
|
|
|
const { test } = pwt;
|
2022-07-01 03:03:01 +03:00
|
|
|
test('pass', async ({ browserName }) => {
|
2021-06-09 01:52:08 +03:00
|
|
|
console.log('\\n%%browser=' + browserName);
|
|
|
|
});
|
|
|
|
`,
|
|
|
|
}, { browser: 'all', workers: 1 });
|
|
|
|
|
|
|
|
expect(result.exitCode).toBe(0);
|
|
|
|
expect(result.passed).toBe(3);
|
|
|
|
expect(result.output.split('\n').filter(line => line.startsWith('%%')).sort()).toEqual([
|
|
|
|
'%%browser=chromium',
|
|
|
|
'%%browser=firefox',
|
|
|
|
'%%browser=webkit',
|
|
|
|
]);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('should run in one browser with --browser', async ({ runInlineTest }) => {
|
|
|
|
const result = await runInlineTest({
|
|
|
|
'playwright.config.ts': `
|
|
|
|
module.exports = { use: { viewport: { width: 800, height: 800 } } };
|
|
|
|
`,
|
|
|
|
'a.test.ts': `
|
|
|
|
const { test } = pwt;
|
2022-07-01 03:03:01 +03:00
|
|
|
test('pass', async ({ browserName }) => {
|
2021-06-09 01:52:08 +03:00
|
|
|
console.log('\\n%%browser=' + browserName);
|
|
|
|
});
|
|
|
|
`,
|
|
|
|
}, { browser: 'webkit', workers: 1 });
|
|
|
|
|
|
|
|
expect(result.exitCode).toBe(0);
|
|
|
|
expect(result.passed).toBe(1);
|
|
|
|
expect(result.output.split('\n').filter(line => line.startsWith('%%')).sort()).toEqual([
|
|
|
|
'%%browser=webkit',
|
|
|
|
]);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('should complain with projects and --browser', async ({ runInlineTest }) => {
|
|
|
|
const result = await runInlineTest({
|
|
|
|
'playwright.config.ts': `
|
|
|
|
module.exports = { projects: [ {} ] };
|
|
|
|
`,
|
|
|
|
'a.test.ts': `
|
|
|
|
const { test } = pwt;
|
|
|
|
test('pass', async ({ page }) => {
|
|
|
|
});
|
|
|
|
`,
|
|
|
|
}, { browser: 'webkit', workers: 1 });
|
|
|
|
|
|
|
|
expect(result.exitCode).toBe(1);
|
|
|
|
expect(result.passed).toBe(0);
|
|
|
|
expect(result.output).toContain('Cannot use --browser option when configuration file defines projects');
|
|
|
|
});
|
|
|
|
|
2022-05-02 18:55:14 +03:00
|
|
|
test('should override any headless option with --headed', async ({ runInlineTest }) => {
|
|
|
|
const result = await runInlineTest({
|
|
|
|
'playwright.config.ts': `
|
|
|
|
module.exports = { projects: [
|
|
|
|
{ name: 'a', use: { headless: true } }
|
|
|
|
] };
|
|
|
|
`,
|
|
|
|
'a.test.ts': `
|
|
|
|
const { test } = pwt;
|
|
|
|
test('example', async ({ page }) => {
|
|
|
|
expect(await page.evaluate(() => navigator.userAgent)).not.toContain('Headless');
|
|
|
|
});
|
|
|
|
`,
|
|
|
|
}, { workers: 1, headed: true });
|
|
|
|
expect(result.exitCode).toBe(0);
|
|
|
|
expect(result.passed).toBe(1);
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2021-07-23 19:04:20 +03:00
|
|
|
test('should not override use:browserName without projects', async ({ runInlineTest }) => {
|
|
|
|
const result = await runInlineTest({
|
|
|
|
'playwright.config.ts': `
|
|
|
|
module.exports = { use: { browserName: 'webkit' } };
|
|
|
|
`,
|
|
|
|
'a.test.ts': `
|
|
|
|
const { test } = pwt;
|
2022-07-27 21:27:53 +03:00
|
|
|
test('pass', async ({ browserName }) => {
|
2021-07-23 19:04:20 +03:00
|
|
|
console.log('\\n%%browser=' + browserName);
|
|
|
|
});
|
|
|
|
`,
|
|
|
|
}, { workers: 1 });
|
|
|
|
|
|
|
|
expect(result.exitCode).toBe(0);
|
|
|
|
expect(result.passed).toBe(1);
|
|
|
|
expect(result.output.split('\n').filter(line => line.startsWith('%%')).sort()).toEqual([
|
|
|
|
'%%browser=webkit',
|
|
|
|
]);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('should override use:browserName with --browser', async ({ runInlineTest }) => {
|
|
|
|
const result = await runInlineTest({
|
|
|
|
'playwright.config.ts': `
|
|
|
|
module.exports = { use: { browserName: 'webkit' } };
|
|
|
|
`,
|
|
|
|
'a.test.ts': `
|
|
|
|
const { test } = pwt;
|
2022-07-27 21:27:53 +03:00
|
|
|
test('pass', async ({ browserName }) => {
|
2021-07-23 19:04:20 +03:00
|
|
|
console.log('\\n%%browser=' + browserName);
|
|
|
|
});
|
|
|
|
`,
|
|
|
|
}, { browser: 'firefox', workers: 1 });
|
|
|
|
|
|
|
|
expect(result.exitCode).toBe(0);
|
|
|
|
expect(result.passed).toBe(1);
|
|
|
|
expect(result.output.split('\n').filter(line => line.startsWith('%%')).sort()).toEqual([
|
|
|
|
'%%browser=firefox',
|
|
|
|
]);
|
|
|
|
});
|
|
|
|
|
2021-08-10 04:09:11 +03:00
|
|
|
test('should respect context options in various contexts', async ({ runInlineTest }, testInfo) => {
|
|
|
|
const result = await runInlineTest({
|
|
|
|
'playwright.config.ts': `
|
|
|
|
module.exports = { use: { viewport: { width: 500, height: 500 } } };
|
|
|
|
`,
|
|
|
|
'a.test.ts': `
|
|
|
|
import fs from 'fs';
|
|
|
|
import os from 'os';
|
|
|
|
import path from 'path';
|
|
|
|
import rimraf from 'rimraf';
|
|
|
|
|
|
|
|
const { test } = pwt;
|
2022-06-08 22:46:39 +03:00
|
|
|
test.use({ locale: 'fr-FR' });
|
2021-08-10 04:09:11 +03:00
|
|
|
|
|
|
|
let context;
|
|
|
|
test.beforeAll(async ({ browser }) => {
|
|
|
|
context = await browser.newContext();
|
|
|
|
});
|
|
|
|
|
|
|
|
test.afterAll(async () => {
|
|
|
|
await context.close();
|
|
|
|
});
|
|
|
|
|
|
|
|
test('shared context', async ({}) => {
|
|
|
|
const page = await context.newPage();
|
|
|
|
expect(page.viewportSize()).toEqual({ width: 500, height: 500 });
|
2022-06-08 22:46:39 +03:00
|
|
|
expect(await page.evaluate(() => navigator.language)).toBe('fr-FR');
|
2021-08-10 04:09:11 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
test('own context', async ({ browser }) => {
|
|
|
|
const page = await browser.newPage();
|
|
|
|
expect(page.viewportSize()).toEqual({ width: 500, height: 500 });
|
2022-06-08 22:46:39 +03:00
|
|
|
expect(await page.evaluate(() => navigator.language)).toBe('fr-FR');
|
2021-08-10 04:09:11 +03:00
|
|
|
await page.close();
|
|
|
|
});
|
|
|
|
|
|
|
|
test('default context', async ({ page }) => {
|
|
|
|
expect(page.viewportSize()).toEqual({ width: 500, height: 500 });
|
2022-06-08 22:46:39 +03:00
|
|
|
expect(await page.evaluate(() => navigator.language)).toBe('fr-FR');
|
2021-08-10 04:09:11 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
test('persistent context', async ({ playwright, browserName }) => {
|
|
|
|
const dir = await fs.promises.mkdtemp(path.join(os.tmpdir(), 'user-data-dir-'));
|
|
|
|
const context = await playwright[browserName].launchPersistentContext(dir);
|
|
|
|
const page = context.pages()[0];
|
|
|
|
|
|
|
|
expect(page.viewportSize()).toEqual({ width: 500, height: 500 });
|
2022-06-08 22:46:39 +03:00
|
|
|
expect(await page.evaluate(() => navigator.language)).toBe('fr-FR');
|
2021-08-10 04:09:11 +03:00
|
|
|
|
|
|
|
await context.close();
|
|
|
|
rimraf.sync(dir);
|
|
|
|
});
|
2021-11-29 20:21:15 +03:00
|
|
|
|
|
|
|
test('another browser', async ({ playwright, browserName }) => {
|
|
|
|
const browser = await playwright.webkit.launch();
|
|
|
|
const page = await browser.newPage();
|
|
|
|
|
2022-06-08 22:46:39 +03:00
|
|
|
expect(await page.evaluate(() => navigator.language)).toBe('fr-FR');
|
2021-11-29 20:21:15 +03:00
|
|
|
|
|
|
|
await browser.close();
|
|
|
|
});
|
2021-08-10 04:09:11 +03:00
|
|
|
`,
|
|
|
|
}, { workers: 1 });
|
|
|
|
|
|
|
|
expect(result.exitCode).toBe(0);
|
2021-11-29 20:21:15 +03:00
|
|
|
expect(result.passed).toBe(5);
|
2021-08-10 04:09:11 +03:00
|
|
|
});
|
|
|
|
|
2022-01-28 21:51:55 +03:00
|
|
|
test('should respect headless in launchPersistent', async ({ runInlineTest }) => {
|
|
|
|
const result = await runInlineTest({
|
|
|
|
'playwright.config.ts': `
|
|
|
|
module.exports = { use: { headless: false } };
|
|
|
|
`,
|
|
|
|
'a.test.ts': `
|
|
|
|
import fs from 'fs';
|
|
|
|
import os from 'os';
|
|
|
|
import path from 'path';
|
|
|
|
import rimraf from 'rimraf';
|
|
|
|
|
|
|
|
const { test } = pwt;
|
|
|
|
|
|
|
|
test('persistent context', async ({ playwright, browserName }) => {
|
|
|
|
const dir = await fs.promises.mkdtemp(path.join(os.tmpdir(), 'user-data-dir-'));
|
|
|
|
const context = await playwright[browserName].launchPersistentContext(dir);
|
|
|
|
const page = context.pages()[0];
|
|
|
|
expect(await page.evaluate(() => navigator.userAgent)).not.toContain('Headless');
|
|
|
|
await context.close();
|
|
|
|
rimraf.sync(dir);
|
|
|
|
});
|
|
|
|
`,
|
|
|
|
}, { workers: 1 });
|
2022-02-10 02:30:14 +03:00
|
|
|
|
|
|
|
expect(result.exitCode).toBe(0);
|
|
|
|
expect(result.passed).toBe(1);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('should respect headless in modifiers that run before tests', async ({ runInlineTest }) => {
|
|
|
|
const result = await runInlineTest({
|
|
|
|
'playwright.config.ts': `
|
|
|
|
module.exports = { use: { headless: false } };
|
|
|
|
`,
|
|
|
|
'a.test.ts': `
|
|
|
|
const { test } = pwt;
|
|
|
|
|
|
|
|
test.skip(({ browser }) => false);
|
|
|
|
|
|
|
|
test('should work', async ({ page }) => {
|
|
|
|
expect(await page.evaluate(() => navigator.userAgent)).not.toContain('Headless');
|
|
|
|
});
|
|
|
|
`,
|
|
|
|
}, { workers: 1 });
|
2022-01-28 21:51:55 +03:00
|
|
|
|
|
|
|
expect(result.exitCode).toBe(0);
|
|
|
|
expect(result.passed).toBe(1);
|
|
|
|
});
|
|
|
|
|
2021-09-04 00:21:25 +03:00
|
|
|
test('should call logger from launchOptions config', async ({ runInlineTest }, testInfo) => {
|
|
|
|
const result = await runInlineTest({
|
|
|
|
'a.test.ts': `
|
|
|
|
const { test } = pwt;
|
|
|
|
const log = [];
|
|
|
|
test.use({
|
|
|
|
launchOptions: {
|
|
|
|
logger: {
|
|
|
|
log: (name, severity, message) => log.push({name, severity, message}),
|
|
|
|
isEnabled: (name, severity) => severity !== 'verbose'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2021-11-19 09:30:09 +03:00
|
|
|
test('should support config logger', async ({browser, context}) => {
|
2021-09-04 00:21:25 +03:00
|
|
|
expect(browser.version()).toBeTruthy();
|
|
|
|
expect(log.length > 0).toBeTruthy();
|
|
|
|
expect(log.filter(item => item.severity === 'info').length > 0).toBeTruthy();
|
2021-11-19 09:30:09 +03:00
|
|
|
expect(log.filter(item => item.message.includes('browser.newContext started')).length > 0).toBeTruthy();
|
|
|
|
expect(log.filter(item => item.message.includes('browser.newContext succeeded')).length > 0).toBeTruthy();
|
2021-09-04 00:21:25 +03:00
|
|
|
});
|
|
|
|
`,
|
|
|
|
}, { workers: 1 });
|
|
|
|
|
|
|
|
expect(result.exitCode).toBe(0);
|
|
|
|
expect(result.passed).toBe(1);
|
|
|
|
});
|
|
|
|
|
2021-06-18 01:09:38 +03:00
|
|
|
test('should report error and pending operations on timeout', async ({ runInlineTest }, testInfo) => {
|
|
|
|
const result = await runInlineTest({
|
|
|
|
'a.test.ts': `
|
|
|
|
const { test } = pwt;
|
|
|
|
test('timedout', async ({ page }) => {
|
|
|
|
await page.setContent('<div>Click me</div>');
|
|
|
|
await Promise.all([
|
|
|
|
page.click('text=Missing'),
|
|
|
|
page.textContent('text=More missing'),
|
|
|
|
]);
|
|
|
|
});
|
|
|
|
`,
|
|
|
|
}, { workers: 1, timeout: 2000 });
|
|
|
|
|
|
|
|
expect(result.exitCode).toBe(1);
|
|
|
|
expect(result.passed).toBe(0);
|
|
|
|
expect(result.failed).toBe(1);
|
|
|
|
expect(result.output).toContain('Pending operations:');
|
|
|
|
expect(result.output).toContain('- page.click at a.test.ts:9:16');
|
|
|
|
expect(result.output).toContain('- page.textContent at a.test.ts:10:16');
|
2021-09-18 01:24:15 +03:00
|
|
|
expect(result.output).toContain('waiting for selector');
|
2022-02-01 04:14:59 +03:00
|
|
|
expect(stripAnsi(result.output)).toContain(`10 | page.textContent('text=More missing'),`);
|
2021-06-18 01:09:38 +03:00
|
|
|
});
|
|
|
|
|
2021-09-28 20:56:50 +03:00
|
|
|
test('should report error on timeout with shared page', async ({ runInlineTest }, testInfo) => {
|
|
|
|
const result = await runInlineTest({
|
|
|
|
'a.test.ts': `
|
|
|
|
const { test } = pwt;
|
|
|
|
let page;
|
|
|
|
test.beforeAll(async ({ browser }) => {
|
|
|
|
page = await browser.newPage();
|
|
|
|
});
|
|
|
|
test('passed', async () => {
|
|
|
|
await page.setContent('<div>Click me</div>');
|
|
|
|
});
|
|
|
|
test('timedout', async () => {
|
|
|
|
await page.click('text=Missing');
|
|
|
|
});
|
|
|
|
`,
|
|
|
|
}, { workers: 1, timeout: 2000 });
|
|
|
|
|
|
|
|
expect(result.exitCode).toBe(1);
|
|
|
|
expect(result.passed).toBe(1);
|
|
|
|
expect(result.failed).toBe(1);
|
|
|
|
expect(result.output).toContain('waiting for selector "text=Missing"');
|
2022-02-01 04:14:59 +03:00
|
|
|
expect(stripAnsi(result.output)).toContain(`14 | await page.click('text=Missing');`);
|
2021-09-28 20:56:50 +03:00
|
|
|
});
|
|
|
|
|
2022-03-09 18:26:46 +03:00
|
|
|
test('should report error from beforeAll timeout', async ({ runInlineTest }, testInfo) => {
|
2021-11-19 01:36:55 +03:00
|
|
|
const result = await runInlineTest({
|
|
|
|
'a.test.ts': `
|
|
|
|
const { test } = pwt;
|
|
|
|
test.beforeAll(async ({ browser }) => {
|
|
|
|
const page = await browser.newPage();
|
|
|
|
await page.setContent('<div>Click me</div>');
|
|
|
|
await Promise.all([
|
|
|
|
page.click('text=Missing'),
|
|
|
|
page.textContent('text=More missing'),
|
|
|
|
]);
|
|
|
|
});
|
|
|
|
test('ignored', () => {});
|
|
|
|
`,
|
|
|
|
}, { workers: 1, timeout: 2000 });
|
|
|
|
|
|
|
|
expect(result.exitCode).toBe(1);
|
|
|
|
expect(result.passed).toBe(0);
|
|
|
|
expect(result.failed).toBe(1);
|
2022-07-01 03:05:08 +03:00
|
|
|
expect(result.output).toContain('"beforeAll" hook timeout of 2000ms exceeded.');
|
2021-11-19 01:36:55 +03:00
|
|
|
expect(result.output).toContain('waiting for selector');
|
2022-02-01 04:14:59 +03:00
|
|
|
expect(stripAnsi(result.output)).toContain(`11 | page.textContent('text=More missing'),`);
|
2021-11-19 01:36:55 +03:00
|
|
|
});
|
|
|
|
|
2021-09-10 07:20:26 +03:00
|
|
|
test('should not report waitForEventInfo as pending', async ({ runInlineTest }, testInfo) => {
|
|
|
|
const result = await runInlineTest({
|
|
|
|
'a.test.ts': `
|
|
|
|
const { test } = pwt;
|
|
|
|
test('timedout', async ({ page }) => {
|
|
|
|
await page.setContent('<div>Click me</div>');
|
|
|
|
await page.waitForLoadState('networkidle');
|
|
|
|
await page.click('text=Missing');
|
|
|
|
});
|
|
|
|
`,
|
2022-07-01 03:03:01 +03:00
|
|
|
}, { workers: 1, timeout: 5000 });
|
2021-09-10 07:20:26 +03:00
|
|
|
|
|
|
|
expect(result.exitCode).toBe(1);
|
|
|
|
expect(result.passed).toBe(0);
|
|
|
|
expect(result.failed).toBe(1);
|
|
|
|
expect(result.output).toContain('Pending operations:');
|
|
|
|
expect(result.output).toContain('- page.click at a.test.ts:9:20');
|
|
|
|
expect(result.output).not.toContain('- page.waitForLoadState');
|
|
|
|
});
|
|
|
|
|
2021-08-10 04:09:11 +03:00
|
|
|
test('should throw when using page in beforeAll', async ({ runInlineTest }, testInfo) => {
|
|
|
|
const result = await runInlineTest({
|
|
|
|
'a.test.ts': `
|
|
|
|
const { test } = pwt;
|
2021-09-01 23:41:35 +03:00
|
|
|
test.beforeAll(() => {});
|
2021-08-10 04:09:11 +03:00
|
|
|
test.beforeAll(async ({ page }) => {
|
|
|
|
});
|
|
|
|
test('ok', async ({ page }) => {
|
|
|
|
});
|
|
|
|
`,
|
|
|
|
}, { workers: 1 });
|
|
|
|
|
|
|
|
expect(result.exitCode).toBe(1);
|
|
|
|
expect(result.passed).toBe(0);
|
2022-07-29 00:07:28 +03:00
|
|
|
expect(result.output).toContain(`Error: "context" and "page" fixtures are not supported in "beforeAll"`);
|
2021-08-10 04:09:11 +03:00
|
|
|
});
|
|
|
|
|
2021-07-29 01:43:37 +03:00
|
|
|
test('should report click error on sigint', async ({ runInlineTest }) => {
|
|
|
|
test.skip(process.platform === 'win32', 'No sending SIGINT on Windows');
|
|
|
|
|
|
|
|
const result = await runInlineTest({
|
|
|
|
'a.test.ts': `
|
|
|
|
const { test } = pwt;
|
|
|
|
test('timedout', async ({ page }) => {
|
|
|
|
await page.setContent('<div>Click me</div>');
|
|
|
|
const promise = page.click('text=Missing');
|
|
|
|
await new Promise(f => setTimeout(f, 100));
|
|
|
|
console.log('\\n%%SEND-SIGINT%%');
|
|
|
|
await promise;
|
|
|
|
});
|
|
|
|
`,
|
|
|
|
}, { workers: 1 }, {}, { sendSIGINTAfter: 1 });
|
|
|
|
|
|
|
|
expect(result.exitCode).toBe(130);
|
|
|
|
expect(result.passed).toBe(0);
|
|
|
|
expect(result.failed).toBe(0);
|
2022-08-02 22:55:43 +03:00
|
|
|
expect(result.interrupted).toBe(1);
|
2022-02-01 04:14:59 +03:00
|
|
|
expect(stripAnsi(result.output)).toContain(`8 | const promise = page.click('text=Missing');`);
|
2021-07-29 01:43:37 +03:00
|
|
|
});
|
|
|
|
|
2021-06-09 01:52:08 +03:00
|
|
|
test('should work with video: retain-on-failure', async ({ runInlineTest }, testInfo) => {
|
|
|
|
const result = await runInlineTest({
|
|
|
|
'playwright.config.ts': `
|
2021-07-23 19:04:20 +03:00
|
|
|
module.exports = { use: { video: 'retain-on-failure' }, name: 'chromium' };
|
2021-06-09 01:52:08 +03:00
|
|
|
`,
|
|
|
|
'a.test.ts': `
|
|
|
|
const { test } = pwt;
|
|
|
|
test('pass', async ({ page }) => {
|
|
|
|
await page.setContent('<div>PASS</div>');
|
|
|
|
await page.waitForTimeout(3000);
|
|
|
|
test.expect(1 + 1).toBe(2);
|
|
|
|
});
|
|
|
|
test('fail', async ({ page }) => {
|
|
|
|
await page.setContent('<div>FAIL</div>');
|
|
|
|
await page.waitForTimeout(3000);
|
|
|
|
test.expect(1 + 1).toBe(1);
|
|
|
|
});
|
|
|
|
`,
|
|
|
|
}, { workers: 1 });
|
|
|
|
|
|
|
|
expect(result.exitCode).toBe(1);
|
|
|
|
expect(result.passed).toBe(1);
|
|
|
|
expect(result.failed).toBe(1);
|
|
|
|
|
|
|
|
const dirPass = testInfo.outputPath('test-results', 'a-pass-chromium');
|
|
|
|
const videoPass = fs.existsSync(dirPass) ? fs.readdirSync(dirPass).find(file => file.endsWith('webm')) : undefined;
|
|
|
|
expect(videoPass).toBeFalsy();
|
|
|
|
|
|
|
|
const videoFail = fs.readdirSync(testInfo.outputPath('test-results', 'a-fail-chromium')).find(file => file.endsWith('webm'));
|
|
|
|
expect(videoFail).toBeTruthy();
|
|
|
|
});
|
|
|
|
|
2021-06-17 02:05:30 +03:00
|
|
|
test('should work with video: on-first-retry', async ({ runInlineTest }, testInfo) => {
|
2021-06-09 01:52:08 +03:00
|
|
|
const result = await runInlineTest({
|
|
|
|
'playwright.config.ts': `
|
2021-07-23 19:04:20 +03:00
|
|
|
module.exports = { use: { video: 'on-first-retry' }, retries: 1, name: 'chromium' };
|
2021-06-09 01:52:08 +03:00
|
|
|
`,
|
|
|
|
'a.test.ts': `
|
|
|
|
const { test } = pwt;
|
|
|
|
test('pass', async ({ page }) => {
|
|
|
|
await page.setContent('<div>PASS</div>');
|
|
|
|
await page.waitForTimeout(3000);
|
|
|
|
test.expect(1 + 1).toBe(2);
|
|
|
|
});
|
|
|
|
test('fail', async ({ page }) => {
|
|
|
|
await page.setContent('<div>FAIL</div>');
|
|
|
|
await page.waitForTimeout(3000);
|
|
|
|
test.expect(1 + 1).toBe(1);
|
|
|
|
});
|
|
|
|
`,
|
|
|
|
}, { workers: 1 });
|
|
|
|
|
|
|
|
expect(result.exitCode).toBe(1);
|
|
|
|
expect(result.passed).toBe(1);
|
|
|
|
expect(result.failed).toBe(1);
|
|
|
|
|
|
|
|
const dirPass = testInfo.outputPath('test-results', 'a-pass-chromium');
|
|
|
|
expect(fs.existsSync(dirPass)).toBeFalsy();
|
|
|
|
|
|
|
|
const dirFail = testInfo.outputPath('test-results', 'a-fail-chromium');
|
|
|
|
expect(fs.existsSync(dirFail)).toBeFalsy();
|
|
|
|
|
2021-08-04 03:07:57 +03:00
|
|
|
const dirRetry = testInfo.outputPath('test-results', 'a-fail-chromium-retry1');
|
|
|
|
const videoFailRetry = fs.readdirSync(dirRetry).find(file => file.endsWith('webm'));
|
2021-06-09 01:52:08 +03:00
|
|
|
expect(videoFailRetry).toBeTruthy();
|
2021-08-04 03:07:57 +03:00
|
|
|
|
|
|
|
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',
|
2022-06-20 23:37:31 +03:00
|
|
|
path: path.join(dirRetry, videoFailRetry!),
|
2021-08-04 03:07:57 +03:00
|
|
|
}]);
|
2021-06-09 01:52:08 +03:00
|
|
|
});
|
2021-06-16 17:51:54 +03:00
|
|
|
|
2021-07-23 19:04:20 +03:00
|
|
|
test('should work with video size', async ({ runInlineTest }, testInfo) => {
|
2021-06-16 17:51:54 +03:00
|
|
|
const result = await runInlineTest({
|
|
|
|
'playwright.config.js': `
|
|
|
|
module.exports = {
|
|
|
|
use: { video: { mode: 'on', size: { width: 220, height: 110 } } },
|
2021-07-23 19:04:20 +03:00
|
|
|
name: 'chromium',
|
2021-06-16 17:51:54 +03:00
|
|
|
preserveOutput: 'always',
|
|
|
|
};
|
|
|
|
`,
|
|
|
|
'a.test.ts': `
|
|
|
|
const { test } = pwt;
|
|
|
|
test('pass', async ({ page }) => {
|
|
|
|
await page.setContent('<div>PASS</div>');
|
|
|
|
await page.waitForTimeout(3000);
|
|
|
|
test.expect(1 + 1).toBe(2);
|
|
|
|
});
|
|
|
|
`,
|
|
|
|
}, { workers: 1 });
|
|
|
|
expect(result.exitCode).toBe(0);
|
|
|
|
expect(result.passed).toBe(1);
|
2021-07-23 19:04:20 +03:00
|
|
|
const folder = testInfo.outputPath(`test-results/a-pass-chromium/`);
|
2021-06-16 17:51:54 +03:00
|
|
|
const [file] = fs.readdirSync(folder);
|
|
|
|
const videoPlayer = new VideoPlayer(path.join(folder, file));
|
|
|
|
expect(videoPlayer.videoWidth).toBe(220);
|
|
|
|
expect(videoPlayer.videoHeight).toBe(110);
|
|
|
|
});
|
2022-01-26 18:43:07 +03:00
|
|
|
|
|
|
|
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();
|
|
|
|
});
|
2022-05-18 22:03:47 +03:00
|
|
|
|
|
|
|
test('should pass fixture defaults to tests', async ({ runInlineTest }) => {
|
|
|
|
const result = await runInlineTest({
|
|
|
|
'playwright.config.js': `
|
|
|
|
module.exports = {};
|
|
|
|
`,
|
|
|
|
'a.test.ts': `
|
|
|
|
const { test } = pwt;
|
|
|
|
test('pass', async ({ acceptDownloads, actionTimeout, headless, javaScriptEnabled, navigationTimeout }) => {
|
|
|
|
expect(acceptDownloads).toBe(true);
|
|
|
|
expect(actionTimeout).toBe(0);
|
|
|
|
expect(headless).toBe(true);
|
|
|
|
expect(javaScriptEnabled).toBe(true);
|
|
|
|
expect(navigationTimeout).toBe(0);
|
|
|
|
});
|
|
|
|
`,
|
|
|
|
}, { workers: 1 });
|
|
|
|
expect(result.exitCode).toBe(0);
|
|
|
|
expect(result.passed).toBe(1);
|
|
|
|
});
|