chore(test-runner): better error message if page gets used inside beforeAll (#16012)

This commit is contained in:
Max Schmitt 2022-07-28 23:07:28 +02:00 committed by GitHub
parent b479869ddc
commit a089bf3df5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 3 deletions

View File

@ -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(),

View File

@ -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 }) => {