0

The layout of my test is something like

test.describe("...", () => {
   let p: Page;
   test.beforeEach(async({browser}) => {
      p = await (await browser.newContext()).newPage();
   }
   test(...);
   test(...);
   test.afterEach(() => {
      p.close();
   })
}

I noticed that the tests were flaky. The solution was to remove the page close after each test. My question would be how the lifecycle of the test hooks works? It seems like sometimes the before each hook happens before the after each hook of a previous test since the page appeared to be closed before the started test was finished, even when not being run in parallel.

lef
  • 67
  • 4

1 Answers1

1

You need to await p.close() as it returns a promise. If you don't await the next test will start before the close() has completed.

A user
  • 26
  • 1