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
chore(test-runner): better error message if page gets used inside beforeAll (#16012)
Max Schmitta089bf3df5c0
diff --git a/packages/playwright-test/src/index.ts b/packages/playwright-test/src/index.tsindex 586b433871..1c5abe2dc9 100644--- a/packages/playwright-test/src/index.ts+++ b/packages/playwright-test/src/index.ts@@ -463,8 +463,13 @@ export const test = _baseTest.extend<TestFixtures, WorkerFixtures>({await use(async options => {const hook = hookType(testInfo);- if (hook)- throw new Error(`"context" and "page" fixtures are not supported in ${hook}. Use browser.newContext() instead.`);+ if (hook) {+ throw new Error([+ `"context" and "page" fixtures are not supported in "${hook}" since they are created on a per-test basis.`,+ `If you would like to reuse a single page between tests, create context manually with browser.newContext(). See https://aka.ms/playwright/reuse-page for details.`,+ `If you would like to configure your page before each test, do that in beforeEach hook instead.`,+ ].join('\n'));+ }const videoOptions: BrowserContextOptions = captureVideo ? {recordVideo: {dir: _artifactsDir(),diff --git a/tests/playwright-test/playwright.spec.ts b/tests/playwright-test/playwright.spec.tsindex ecb9c1160f..54e251d085 100644--- a/tests/playwright-test/playwright.spec.ts+++ b/tests/playwright-test/playwright.spec.ts@@ -428,7 +428,7 @@ test('should throw when using page in beforeAll', async ({ runInlineTest }, testexpect(result.exitCode).toBe(1);expect(result.passed).toBe(0);- expect(result.output).toContain(`Error: "context" and "page" fixtures are not supported in beforeAll. Use browser.newContext() instead.`);+ expect(result.output).toContain(`Error: "context" and "page" fixtures are not supported in "beforeAll"`);});test('should report click error on sigint', async ({ runInlineTest }) => {