My testing framework setup looks something like this:
test.describe("...", () => {
let p: Page;
test.beforeEach(async({browser}) => {
p = await (await browser.newContext()).newPage();
}
test(...);
test(...);
test.afterEach(() => {
p.close();
})
}
I encountered issues with fluctuating test results. The problem was resolved by removing the page close action after each test. This leads me to wonder about the timing and sequencing of test hooks. It seems that at times, the before each hook occurs before the after each hook of a previous test, leading to premature closure of the page even when tests are not running concurrently.