-
Notifications
You must be signed in to change notification settings - Fork 3.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Bug]: Browser object is not restarted after a passed test for two consecutive test.describe #30289
Comments
I am also facing this issue |
Playwright has 3 fundamental objects when interacting with the browser.
In your case, you forgot to close the Browser Context which you were creating in issue 1, this one was then still alive for the second test. For the issue 2, you were closing the browser, which we re-use for multiple tests, hence you then get an error in the second test, that the browser is already closed. Doing the following would fix it: diff --git a/tests/Issue-1-1st-test-passed.spec.ts b/tests/Issue-1-1st-test-passed.spec.ts
index 7b3dd9d..5381699 100644
--- a/tests/Issue-1-1st-test-passed.spec.ts
+++ b/tests/Issue-1-1st-test-passed.spec.ts
@@ -8,6 +8,7 @@ test.describe('Example - Describe 1', () => {
// Expect a title "to contain" a substring.
await expect(page).toHaveTitle(/Playwright/);
+ await context.close();
})
})
@@ -22,5 +23,7 @@ test.describe('Example - Describe 2', () => {
// Expects page to have a heading with the name of Installation.
await expect(page.getByRole('heading', { name: 'Installation' })).toBeVisible();
+ await context.close();
})
})
Issue 2: diff --git a/tests/Issue-2-1st-test-passed-and-afterEach-Close.spec.ts b/tests/Issue-2-1st-test-passed-and-afterEach-Close.spec.ts
index fe176a0..052bae1 100644
--- a/tests/Issue-2-1st-test-passed-and-afterEach-Close.spec.ts
+++ b/tests/Issue-2-1st-test-passed-and-afterEach-Close.spec.ts
@@ -8,10 +8,7 @@ test.describe('Example - Describe 1', () => {
// Expect a title "to contain" a substring.
await expect(page).toHaveTitle(/Playwright/);
- })
-
- test.afterEach(async ({ browser }) => {
- await browser.close()
+ await context.close()
})
})
@@ -26,5 +23,6 @@ test.describe('Example - Describe 2', () => {
// Expects page to have a heading with the name of Installation.
await expect(page.getByRole('heading', { name: 'Installation' })).toBeVisible();
+ await context.close();
})
}) See here: https://playwright.dev/docs/api/class-browsercontext |
Hey @mxschmitt , I think I have a different problem, I'm writing a POM project. here is my test:
SearchPage:
When I run the test, for some reason, every time in a different area on the test the following error displayed: |
Yes your issue is different. In order to not mix up the issues, please file a new issue with code we can run locally. But from quickly looking at it, I can already observe the following:
|
Thanks @mxschmitt In any case the issue I am raising is not what you are fixing. By the way, I have implemented a workaround by closing the page. I would explore closing the context in any case |
The reason for that is that Playwright is restarting the worker when a test is failing, see here. Closing as per above. |
Version
1.43
Steps to reproduce
npm install
Expected Behaviour: After the test of the describe is finished, the browser object gets restarted by the framework
npx playwright test Expected-Behaviour-1st-test-failed.spec.ts --headed
You will see:
Issue #1: The browser object is not restarted
npx playwright test Issue-1-1st-test-passed.spec.ts --headed
You will see:
Issue #2: The browser object is forced to close via browser.close(), but the second describe cannot reopened it
npx playwright test Issue-2-1st-test-passed-and-afterEach-Close.spec.ts --headed
You will see:
Bonus: While keeping the use of browser.close at the AfterEach, If there is a third test.describe, while the second test.describe fails, the third one doesn't, it is able to restart the browser object
npx playwright test Bonus-with-3-test-describe.spec.ts --headed
You will see:
Expected behavior
As explained in "Steps to reproduce" the expected behaviour is to close at least the page, in order to not use unneeded memory.
Besides screenshot feature, if not well managed, could save two screenshots while only one needed.
Actual behavior
As explained in "Steps to reproduce" the actual behaviour is that you end up with 2 opened windows
Additional context
No response
Environment
The text was updated successfully, but these errors were encountered: