[Feature] Pause test (`page.pause()`) on failure
See original GitHub issueSometimes I ran Playwright test, the the test failed. The browser is closed before I can inspect it. The trace may not provide enough information (e.g. when debugging websockets or the test failed while waiting for a response from server).
When I run Playwright again with the inspector, I can no longer reproduce the problem.
Since E2E tests can be more prone to heisenbugs, I’d like to suggest having an option to pause the test when a test is failed — before the browser context is closed, so developers will have a chance to investigate what happened.
I have tried this:
test.afterEach(async ({ page }, testInfo) => {
if (testInfo.status !== testInfo.expectedStatus) {
await page.pause()
}
})
However,
- The inspector closes itself because 30 seconds has passed (due to test timeout).
- Stack trace is not shown; there is no indication of what failed.
After a while I came up with this workaround…
// When running outside CI, pause Playwright when a test failed.
// See: https://github.com/microsoft/playwright/issues/10132
test.afterEach(async ({ page }, testInfo) => {
if (!process.env.CI && testInfo.status !== testInfo.expectedStatus) {
process.stderr.write(
`❌ ❌ PLAYWRIGHT TEST FAILURE ❌ ❌\n${
testInfo.error?.stack || testInfo.error
}\n`,
)
testInfo.setTimeout(0)
await page.pause()
}
})
I wish this is available as a CLI flag.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:17
- Comments:14 (4 by maintainers)
Top Results From Across the Web
Protractor Pause On Failure - selenium webdriver
Is there a way to pause automatically on failure? I don't know in advance which test is going to fail, so now I'm...
Read more >Playwright Inspector and page.pause() (#214) - YouTube
Specifically, we take a look at how ` pause ()` and Playwright Inspector can help you to understand what's happening in your tests...
Read more >HTML DOM Audio pause() Method - W3Schools
Definition and Usage. The pause() method halts (pauses) the currently playing audio. Tip: This method is often used together with the play() method....
Read more >await - JavaScript - MDN Web Docs
await is usually used to unwrap promises by passing a Promise as the expression . Using await pauses the execution of its surrounding...
Read more >Pause test suite execution on test case fail - Katalon Community
If it paused, then I could troubleshoot at the point of failure, but because it ... We also need the Pause test suite...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
For me, overriding the timeout using
testInfo.setTimeout(0)
doesn’t work, playwright still exits. Is it just me?If not, how does everybody deal with the fact that playwright will either freeze forever if timeout is 0 and something can’t be found or it will exit, preventing debugging.
There are three problems with this:
@ddaypunk The trace viewer is very helpful in most cases. However, not everything is recorded in traces, e.g. WebSocket messages.
@dgozman Sorry for late reply.
Here’s a small repro.
I run this with:
Then clicked the “Resume” button.
Apparently, when the test is run to the end, the browser is gone, regardless of whether the test failed or passed. Coming from Cypress, when the test finished running, you can still interact with the web page, and having that facility helped us in debugging failed test tremendously.
If a Playwright action failed, it does show in the inspector:
However, a test can also fail due to other reasons. For example, I changed this:
In this case, nothing would show up on the inspector.