Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
TypeScript automationchromechromiume2e-testingelectronend-to-end-testingfirefoxjavascriptplaywrighttesttest-automationtestingtesting-toolswebwebkit
fix(test-runner): fix browser initialization in test modifiers (#11984)
Andrey Lushnikov6904b3294e09
diff --git a/packages/playwright-test/src/index.ts b/packages/playwright-test/src/index.tsindex 56595a18a6..d26f61b52a 100644--- a/packages/playwright-test/src/index.ts+++ b/packages/playwright-test/src/index.ts@@ -88,7 +88,7 @@ export const test = _baseTest.extend<TestFixtures, WorkerFixtures>({await removeFolders([dir]);}, { scope: 'worker' }],- _browserOptions: [async ({ headless, channel, launchOptions }, use) => {+ _browserOptions: [async ({ playwright, headless, channel, launchOptions }, use) => {const options: LaunchOptions = {handleSIGINT: false,timeout: 0,@@ -98,8 +98,13 @@ export const test = _baseTest.extend<TestFixtures, WorkerFixtures>({options.headless = headless;if (channel !== undefined)options.channel = channel;++ for (const browserType of [playwright.chromium, playwright.firefox, playwright.webkit])+ (browserType as any)._defaultLaunchOptions = options;await use(options);- }, { scope: 'worker' }],+ for (const browserType of [playwright.chromium, playwright.firefox, playwright.webkit])+ (browserType as any)._defaultLaunchOptions = undefined;+ }, { scope: 'worker', auto: true }],browser: [async ({ playwright, browserName, connectOptions }, use) => {if (!['chromium', 'firefox', 'webkit'].includes(browserName))@@ -323,7 +328,6 @@ export const test = _baseTest.extend<TestFixtures, WorkerFixtures>({(browserType as any)._onDidCreateContext = onDidCreateBrowserContext;(browserType as any)._onWillCloseContext = onWillCloseContext;(browserType as any)._defaultContextOptions = _combinedContextOptions;- (browserType as any)._defaultLaunchOptions = _browserOptions;const existingContexts = Array.from((browserType as any)._contexts) as BrowserContext[];await Promise.all(existingContexts.map(onDidCreateBrowserContext));}@@ -365,7 +369,6 @@ export const test = _baseTest.extend<TestFixtures, WorkerFixtures>({(browserType as any)._onDidCreateContext = undefined;(browserType as any)._onWillCloseContext = undefined;(browserType as any)._defaultContextOptions = undefined;- (browserType as any)._defaultLaunchOptions = undefined;}leftoverContexts.forEach(context => (context as any)._instrumentation.removeAllListeners());for (const context of (playwright.request as any)._contexts)diff --git a/tests/playwright-test/playwright.spec.ts b/tests/playwright-test/playwright.spec.tsindex ca217e010a..147e20a45c 100644--- a/tests/playwright-test/playwright.spec.ts+++ b/tests/playwright-test/playwright.spec.ts@@ -257,6 +257,26 @@ test('should respect headless in launchPersistent', async ({ runInlineTest }) =>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 });++ expect(result.exitCode).toBe(0);+ expect(result.passed).toBe(1);+});+test('should call logger from launchOptions config', async ({ runInlineTest }, testInfo) => {const result = await runInlineTest({'a.test.ts': `