Rayrun
← Back to Discord Forum

playwright 1.4 closes apiRequestContext after beforeAll, causing context has been closed error

I have noticed with issue only with 1.4 version of playwright. Does not happen in 1.39.

Has anything changed in how apiRequestContext is shared between beforeAll and test?

Example:

let apiClass;
test.beforeAll(async ({ request }) => {
  apiClass = new ApiClass(requst);
  ... do something ...
});

test('first test', async () => {
  await apiClass.doSomething();
});

when apiClass method is called within test, the following error shows only in playwright 1.4: Error: apiRequestContext.storageState: Target page, context or browser has been closed

If i reinitialize apiClass within test, error disappears

This thread is trying to answer question "Has the way apiRequestContext is shared between beforeAll and tests changed in Playwright 1.4, and how should it be correctly initialized?"

1 reply

found that that 1.4 for shared request context rquires for it to be defined as follows:

let request = await playwright.request.newContext();```

Related Discord Threads

TwitterGitHubLinkedIn
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 [email protected].