mirror of
https://github.com/microsoft/playwright.git
synced 2024-12-14 13:45:36 +03:00
fix(test runner): do not override browserName when using without --browser (#7806)
This commit is contained in:
parent
827fb80465
commit
bf6482a58d
@ -84,7 +84,8 @@ export function addTestCommand(program: commander.CommanderStatic) {
|
|||||||
async function runTests(args: string[], opts: { [key: string]: any }) {
|
async function runTests(args: string[], opts: { [key: string]: any }) {
|
||||||
await startProfiling();
|
await startProfiling();
|
||||||
|
|
||||||
const browserOpt = opts.browser ? opts.browser.toLowerCase() : 'chromium';
|
if (opts.browser) {
|
||||||
|
const browserOpt = opts.browser.toLowerCase();
|
||||||
if (!['all', 'chromium', 'firefox', 'webkit'].includes(browserOpt))
|
if (!['all', 'chromium', 'firefox', 'webkit'].includes(browserOpt))
|
||||||
throw new Error(`Unsupported browser "${opts.browser}", must be one of "all", "chromium", "firefox" or "webkit"`);
|
throw new Error(`Unsupported browser "${opts.browser}", must be one of "all", "chromium", "firefox" or "webkit"`);
|
||||||
const browserNames = browserOpt === 'all' ? ['chromium', 'firefox', 'webkit'] : [browserOpt];
|
const browserNames = browserOpt === 'all' ? ['chromium', 'firefox', 'webkit'] : [browserOpt];
|
||||||
@ -94,6 +95,7 @@ async function runTests(args: string[], opts: { [key: string]: any }) {
|
|||||||
use: { browserName },
|
use: { browserName },
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
const overrides = overridesFromOptions(opts);
|
const overrides = overridesFromOptions(opts);
|
||||||
if (opts.headed)
|
if (opts.headed)
|
||||||
|
@ -121,6 +121,46 @@ test('should complain with projects and --browser', async ({ runInlineTest }) =>
|
|||||||
expect(result.output).toContain('Cannot use --browser option when configuration file defines projects');
|
expect(result.output).toContain('Cannot use --browser option when configuration file defines projects');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
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;
|
||||||
|
test('pass', async ({ page, browserName }) => {
|
||||||
|
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;
|
||||||
|
test('pass', async ({ page, browserName }) => {
|
||||||
|
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',
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
|
||||||
test('should report error and pending operations on timeout', async ({ runInlineTest }, testInfo) => {
|
test('should report error and pending operations on timeout', async ({ runInlineTest }, testInfo) => {
|
||||||
const result = await runInlineTest({
|
const result = await runInlineTest({
|
||||||
'a.test.ts': `
|
'a.test.ts': `
|
||||||
@ -148,7 +188,7 @@ test('should report error and pending operations on timeout', async ({ runInline
|
|||||||
test('should work with screenshot: only-on-failure', async ({ runInlineTest }, testInfo) => {
|
test('should work with screenshot: only-on-failure', async ({ runInlineTest }, testInfo) => {
|
||||||
const result = await runInlineTest({
|
const result = await runInlineTest({
|
||||||
'playwright.config.ts': `
|
'playwright.config.ts': `
|
||||||
module.exports = { use: { screenshot: 'only-on-failure' } };
|
module.exports = { use: { screenshot: 'only-on-failure' }, name: 'chromium' };
|
||||||
`,
|
`,
|
||||||
'a.test.ts': `
|
'a.test.ts': `
|
||||||
const { test } = pwt;
|
const { test } = pwt;
|
||||||
@ -175,7 +215,7 @@ test('should work with screenshot: only-on-failure', async ({ runInlineTest }, t
|
|||||||
test('should work with video: retain-on-failure', async ({ runInlineTest }, testInfo) => {
|
test('should work with video: retain-on-failure', async ({ runInlineTest }, testInfo) => {
|
||||||
const result = await runInlineTest({
|
const result = await runInlineTest({
|
||||||
'playwright.config.ts': `
|
'playwright.config.ts': `
|
||||||
module.exports = { use: { video: 'retain-on-failure' } };
|
module.exports = { use: { video: 'retain-on-failure' }, name: 'chromium' };
|
||||||
`,
|
`,
|
||||||
'a.test.ts': `
|
'a.test.ts': `
|
||||||
const { test } = pwt;
|
const { test } = pwt;
|
||||||
@ -207,7 +247,7 @@ test('should work with video: retain-on-failure', async ({ runInlineTest }, test
|
|||||||
test('should work with video: on-first-retry', async ({ runInlineTest }, testInfo) => {
|
test('should work with video: on-first-retry', async ({ runInlineTest }, testInfo) => {
|
||||||
const result = await runInlineTest({
|
const result = await runInlineTest({
|
||||||
'playwright.config.ts': `
|
'playwright.config.ts': `
|
||||||
module.exports = { use: { video: 'on-first-retry' }, retries: 1 };
|
module.exports = { use: { video: 'on-first-retry' }, retries: 1, name: 'chromium' };
|
||||||
`,
|
`,
|
||||||
'a.test.ts': `
|
'a.test.ts': `
|
||||||
const { test } = pwt;
|
const { test } = pwt;
|
||||||
@ -238,11 +278,12 @@ test('should work with video: on-first-retry', async ({ runInlineTest }, testInf
|
|||||||
expect(videoFailRetry).toBeTruthy();
|
expect(videoFailRetry).toBeTruthy();
|
||||||
});
|
});
|
||||||
|
|
||||||
test('should work with video size', async ({ runInlineTest, browserName }, testInfo) => {
|
test('should work with video size', async ({ runInlineTest }, testInfo) => {
|
||||||
const result = await runInlineTest({
|
const result = await runInlineTest({
|
||||||
'playwright.config.js': `
|
'playwright.config.js': `
|
||||||
module.exports = {
|
module.exports = {
|
||||||
use: { video: { mode: 'on', size: { width: 220, height: 110 } } },
|
use: { video: { mode: 'on', size: { width: 220, height: 110 } } },
|
||||||
|
name: 'chromium',
|
||||||
preserveOutput: 'always',
|
preserveOutput: 'always',
|
||||||
};
|
};
|
||||||
`,
|
`,
|
||||||
@ -257,7 +298,7 @@ test('should work with video size', async ({ runInlineTest, browserName }, testI
|
|||||||
}, { workers: 1 });
|
}, { workers: 1 });
|
||||||
expect(result.exitCode).toBe(0);
|
expect(result.exitCode).toBe(0);
|
||||||
expect(result.passed).toBe(1);
|
expect(result.passed).toBe(1);
|
||||||
const folder = testInfo.outputPath(`test-results/a-pass-${browserName}/`);
|
const folder = testInfo.outputPath(`test-results/a-pass-chromium/`);
|
||||||
const [file] = fs.readdirSync(folder);
|
const [file] = fs.readdirSync(folder);
|
||||||
const videoPlayer = new VideoPlayer(path.join(folder, file));
|
const videoPlayer = new VideoPlayer(path.join(folder, file));
|
||||||
expect(videoPlayer.videoWidth).toBe(220);
|
expect(videoPlayer.videoWidth).toBe(220);
|
||||||
|
@ -22,6 +22,7 @@ test('should work and remove non-failures', async ({ runInlineTest }, testInfo)
|
|||||||
const result = await runInlineTest({
|
const result = await runInlineTest({
|
||||||
'playwright.config.ts': `
|
'playwright.config.ts': `
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
name: 'chromium',
|
||||||
preserveOutput: 'failures-only',
|
preserveOutput: 'failures-only',
|
||||||
testDir: 'dir',
|
testDir: 'dir',
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user