fix(test-runner): apply default options to all browserTypes (#10507)
This commit is contained in:
parent
11a389c8f9
commit
15053d9b3b
|
|
@ -16,12 +16,12 @@
|
||||||
|
|
||||||
import * as fs from 'fs';
|
import * as fs from 'fs';
|
||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
import type { LaunchOptions, BrowserContextOptions, Page, BrowserContext, BrowserType, Video } from 'playwright-core';
|
import type { LaunchOptions, BrowserContextOptions, Page, BrowserContext, BrowserType, Video, Browser } from 'playwright-core';
|
||||||
import type { TestType, PlaywrightTestArgs, PlaywrightTestOptions, PlaywrightWorkerArgs, PlaywrightWorkerOptions, TestInfo } from '../types/test';
|
import type { TestType, PlaywrightTestArgs, PlaywrightTestOptions, PlaywrightWorkerArgs, PlaywrightWorkerOptions, TestInfo } from '../types/test';
|
||||||
import { rootTestType } from './testType';
|
import { rootTestType } from './testType';
|
||||||
import { createGuid, removeFolders } from 'playwright-core/lib/utils/utils';
|
import { createGuid, removeFolders } from 'playwright-core/lib/utils/utils';
|
||||||
import { GridClient } from 'playwright-core/lib/grid/gridClient';
|
import { GridClient } from 'playwright-core/lib/grid/gridClient';
|
||||||
import { Browser } from 'playwright-core';
|
import { chromium, firefox, webkit } from 'playwright-core';
|
||||||
import { prependToTestError } from './util';
|
import { prependToTestError } from './util';
|
||||||
export { expect } from './expect';
|
export { expect } from './expect';
|
||||||
export const _baseTest: TestType<{}, {}> = rootTestType.test;
|
export const _baseTest: TestType<{}, {}> = rootTestType.test;
|
||||||
|
|
@ -172,7 +172,7 @@ export const test = _baseTest.extend<TestFixtures, WorkerFixtures>({
|
||||||
|
|
||||||
_snapshotSuffix: [process.env.PLAYWRIGHT_DOCKER ? 'docker' : process.platform, { scope: 'worker' }],
|
_snapshotSuffix: [process.env.PLAYWRIGHT_DOCKER ? 'docker' : process.platform, { scope: 'worker' }],
|
||||||
|
|
||||||
_setupContextOptionsAndArtifacts: [async ({ _snapshotSuffix, _browserType, _combinedContextOptions, _artifactsDir, trace, screenshot, actionTimeout, navigationTimeout }, use, testInfo) => {
|
_setupContextOptionsAndArtifacts: [async ({ _snapshotSuffix, _combinedContextOptions, _artifactsDir, trace, screenshot, actionTimeout, navigationTimeout }, use, testInfo) => {
|
||||||
testInfo.snapshotSuffix = _snapshotSuffix;
|
testInfo.snapshotSuffix = _snapshotSuffix;
|
||||||
if (process.env.PWDEBUG)
|
if (process.env.PWDEBUG)
|
||||||
testInfo.setTimeout(0);
|
testInfo.setTimeout(0);
|
||||||
|
|
@ -248,11 +248,13 @@ export const test = _baseTest.extend<TestFixtures, WorkerFixtures>({
|
||||||
};
|
};
|
||||||
|
|
||||||
// 1. Setup instrumentation and process existing contexts.
|
// 1. Setup instrumentation and process existing contexts.
|
||||||
(_browserType as any)._onDidCreateContext = onDidCreateContext;
|
for (const browserType of [chromium, firefox, webkit]) {
|
||||||
(_browserType as any)._onWillCloseContext = onWillCloseContext;
|
(browserType as any)._onDidCreateContext = onDidCreateContext;
|
||||||
(_browserType as any)._defaultContextOptions = _combinedContextOptions;
|
(browserType as any)._onWillCloseContext = onWillCloseContext;
|
||||||
const existingContexts = Array.from((_browserType as any)._contexts) as BrowserContext[];
|
(browserType as any)._defaultContextOptions = _combinedContextOptions;
|
||||||
await Promise.all(existingContexts.map(onDidCreateContext));
|
const existingContexts = Array.from((browserType as any)._contexts) as BrowserContext[];
|
||||||
|
await Promise.all(existingContexts.map(onDidCreateContext));
|
||||||
|
}
|
||||||
|
|
||||||
// 2. Run the test.
|
// 2. Run the test.
|
||||||
await use();
|
await use();
|
||||||
|
|
@ -280,10 +282,13 @@ export const test = _baseTest.extend<TestFixtures, WorkerFixtures>({
|
||||||
};
|
};
|
||||||
|
|
||||||
// 4. Cleanup instrumentation.
|
// 4. Cleanup instrumentation.
|
||||||
const leftoverContexts = Array.from((_browserType as any)._contexts) as BrowserContext[];
|
const leftoverContexts: BrowserContext[] = [];
|
||||||
(_browserType as any)._onDidCreateContext = undefined;
|
for (const browserType of [chromium, firefox, webkit]) {
|
||||||
(_browserType as any)._onWillCloseContext = undefined;
|
leftoverContexts.push(...(browserType as any)._contexts);
|
||||||
(_browserType as any)._defaultContextOptions = undefined;
|
(browserType as any)._onDidCreateContext = undefined;
|
||||||
|
(browserType as any)._onWillCloseContext = undefined;
|
||||||
|
(browserType as any)._defaultContextOptions = undefined;
|
||||||
|
}
|
||||||
leftoverContexts.forEach(context => (context as any)._instrumentation.removeAllListeners());
|
leftoverContexts.forEach(context => (context as any)._instrumentation.removeAllListeners());
|
||||||
|
|
||||||
// 5. Collect artifacts from any non-closed contexts.
|
// 5. Collect artifacts from any non-closed contexts.
|
||||||
|
|
|
||||||
|
|
@ -213,11 +213,20 @@ test('should respect context options in various contexts', async ({ runInlineTes
|
||||||
await context.close();
|
await context.close();
|
||||||
rimraf.sync(dir);
|
rimraf.sync(dir);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('another browser', async ({ playwright, browserName }) => {
|
||||||
|
const browser = await playwright.webkit.launch();
|
||||||
|
const page = await browser.newPage();
|
||||||
|
|
||||||
|
expect(await page.evaluate(() => navigator.language)).toBe('fr-CH');
|
||||||
|
|
||||||
|
await browser.close();
|
||||||
|
});
|
||||||
`,
|
`,
|
||||||
}, { workers: 1 });
|
}, { workers: 1 });
|
||||||
|
|
||||||
expect(result.exitCode).toBe(0);
|
expect(result.exitCode).toBe(0);
|
||||||
expect(result.passed).toBe(4);
|
expect(result.passed).toBe(5);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('should call logger from launchOptions config', async ({ runInlineTest }, testInfo) => {
|
test('should call logger from launchOptions config', async ({ runInlineTest }, testInfo) => {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue