[Feature] Add option to leave browser in dangling state when test finishes/fails
In the cypress UI, you can keep a test in a dangling state, allowing to interact with the application you're testing in the same state as when the test finishes or fails. This is useful for debugging and writing tests.
In the playwright UI mode, this does not seem possible (e.g. the none-headless chrome window always closes on failure or finish and I can't seem to make it stay open at the end of the test to further inspect/test stuff in that specific state). It would be a nice addition.
@sebakerckhof You can achieve this today with VSCode extension by checking "Show browser". In the UI mode, there is no such functionality yet.
This is related to https://github.com/microsoft/playwright/issues/37276
Why was this issue closed?
Thank you for your involvement. This issue was closed due to limited engagement (upvotes/activity), lack of recent activity, and insufficient actionability. To maintain a manageable database, we prioritize issues based on these factors.
If you have additional information not present in this issue that you think will help prioritizing it, please open a new issue and reference this one. More support or clarity on its necessity may prompt a review. Your understanding and cooperation are appreciated.
algo was too eager!
Is there somewhere we could put a breakpoint in the Playwright code to stop the browser from closing as a workaround?
I'm using Webstorm so the VSCode option isn't helpful for me. In my example the test fails due to an element not being found, the Playwright results page opens but the test browser closes, even though the IDE thinks the test is still running (debug mode). It would make more sense to me if the browser stays open in this case, and would make debugging easier.
The VS Code option depends on a nontrivial integration we have between the test runner and our VS Code extension, so that won't work in Webstorm. You should be able to put a page.pause() call just before the failing line in your test script though, which should end up working similarly.
So, as far as I see, is my following statement correct? (see the repro below)
When you overwrite the test fixture and use
Show browserin VSCode, the browser will close once the test is finished (in any state).
If that's the case, then I don't get how one is supposed to use the Record at cursor functionality since the docs state:
If your browser window is not already open then first run the test with 'Show browser' checked and then click the Record at cursor button.
Reproduction
// e2e/repro.spec.ts
import { test as testBase } from "@playwright/test";
import { test } from "./repro_fixture";
const LINK = "https://github.com/";
test("browser unfortunately doesn't stay open", async ({ page, adminPage }) => {
await page.goto(LINK);
await adminPage.goto(LINK);
});
testBase("browser stays open", async ({ page }) => {
await page.goto(LINK);
});
// e2e/repro_fixture.ts
import { test as base, Page } from "@playwright/test";
type UserFixtures = {
adminPage: Page;
};
export * from "@playwright/test";
export const test = base.extend<UserFixtures>({
page: async ({ browser }, use) => {
const browserContext = await browser.newContext();
const userPage = await browserContext.newPage();
// simulate creating new user
await userPage.request.post("/users/sign_in_as_student");
await use(userPage);
await browserContext.close();
},
adminPage: async ({ browser }, use) => {
const browserContext = await browser.newContext();
const userPage = await browserContext.newPage();
// simulate creating new user
await userPage.request.post("/users/sign_in_as_admin");
await use(userPage);
await browserContext.close();
},
});
Note that the browser might stay open for both tests in the beginning. Then, if you execute the tests (in random order) multiple times, you reach a point where the browser consistently closes after the first test, but stays open after the second one finishes.
Can somebody reproduce this on their end or is it a problem with my setup?
(VSCode, Dev Container hosted on GitHub Codespaces, using desktop-lite and connecting via RealVNC)
https://github.com/user-attachments/assets/7fbe3bfa-40bc-40ff-8cb0-073556dcf52e