diff --git a/packages/playwright-test/src/index.ts b/packages/playwright-test/src/index.ts index 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({ 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.ts index 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 }, test expect(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 }) => {