← Back to Discord Forum

Error: Playwright Test did not expect test.beforeAll() to be called here

cherry_picker_01posted in #help-playwright
Open in Discord

After upgrading Playwright to latest version, I've encountered the following issue. In our fixture, we've set up these blocks, but with the latest Playwright versions, it seems that using them is no longer allowed. Can someone please guide?

The error message I'm getting is: "Error: Playwright Test did not expect test.beforeAll() to be called here. The most common reasons for this error include:

Calling test.beforeAll() in a configuration file. Calling test.beforeAll() in a file that is imported by the configuration file. Having two different versions of @playwright/test. This usually happens when one of the dependencies in your package.json depends on @playwright/test."

Fixture file:

import { testSetup } from './test-setup';

import {
loginPage...etc} from '/page-object.ts';

let testPage: Page = null;
export const test = base.extend<{
  loginPage: LoginPage;
  page: async ({ browser }, use) => {
    if (testPage === null) {
      testPage = await browser.newPage();

    await use(testPage);
  loginPage: async ({ page }, use) => {
    await use(new LoginPage(page));

export const expect = test.expect;


export const testSetup = (test) => {
  test.beforeAll(async () => {
    // login & store sessions

  test.beforeEach(async () => {
    // other steps to capture test information for an internal portal

This thread is trying to answer question "How can I resolve the 'Error: Playwright Test did not expect test.beforeAll() to be called here' after upgrading Playwright to the latest version?"

6 replies
  1. where does your base. come from at your fixture?
  2. page:... is too much at your fixture. when you use test/base.extend... it already has a new context etc. so you don´t need page: async... at your fixture. At your test you can access page directly through your fixture.
  3. when you have test('my_test', asyn({loginPage, page, etc})) you have access to everything and you dont need to run .beforeAll/.beforeEach ...async({loginPage.... loaded your data directly when you step into your test.


import { test as base } from '@playwright/test';
import { LoginPage} from 'page-object';

export const test = base.extend<{loginPage: LoginPage}>({
  loginPage: async ({ page }, use) => {
    await use(new LoginPage(page));

  custom_page: async ({ page }, use) => {
    //your custom page and before each test stuff 
    await use(custom_page)
export { expect } from '@playwright/test';


import {test, expect} from 'fixture'

test('my test 1', async ({ custom_page, loginPage}) => {

test('my test 2', async ({loginPage}) => {

If it confuses you let me know. here is a link to fixtures https://playwright.dev/docs/test-fixtures#using-a-fixture


thank you @kalkleiste . When I attempted to introduce the 'custom_page' fixture, it triggered an error message.


Sry my solution is quick and dirty. However, I don't understand why it is necessary for you to have a new context.

Object literal may only specify known properties, and 'custom_page' does not exist in type 'Fixtures<{ loginPage: LoginPage;  ... 74 more ...; pwPage: PwPage; }, {}, PlaywrightTestArgs & PlaywrightTestOptions, PlaywrightWorkerArgs & PlaywrightWorkerOptions>'.ts(2345)```

Would it be okay if I DM you?

@cherry_picker_01: Yeah, sure

Yeah, sure

Related Discord Threads

AboutQuestionsDiscord ForumBrowser ExtensionTagsQA Jobs

Rayrun is a community for QA engineers. I am constantly looking for new ways to add value to people learning Playwright and other browser automation frameworks. If you have feedback, email luc@ray.run.