-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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] throwing from pageerror callback leads to unpredictable behavior #28056
Comments
Perhaps you can consider this approach. test("Example", async ({ page }) => {
// Log all uncaught errors to the terminal
page.on("pageerror", (exception) => {
expect(exception, exception).not.toBeDefined();
});
// Navigate to a page with an exception.
await page.goto('data:text/html,<script>throw new Error("Test")</script>');
}); |
I can partly reproduce the issue with the following snippet. When running in UI mode, I don't see the "Some error", but instead see the expect's error. import { test, expect } from '@playwright/test';
test('a test', async ({ page }) => {
await page.goto('https://playwright.dev');
setTimeout(() => { throw new Error('Some error') }, 500);
await expect(page.locator('.todo-list li')).toHaveCount(10);
}); However, I cannot reproduce the "empty result" issue. @bahmutov Could you please share the full repro, with the actual page url, that triggers the empty result? I suspect it is timing-related. |
Sure, here is a standalone repo https://github.com/bahmutov/pw-on-error ![]() |
@bahmutov Thank you for the repro. I can observe the same: expect actions at the end with an empty log. However, both expects reliably succeed in my case, I guess due to different timing. |
System info
Source code
I am trying to fail the test if the page throws any errors.
The UI test mode shows really unpredictable behavior, see the video below. Every time I click on the run button, it does something differently, and sometimes the results disappear.
throw-on-pageerror.mp4
Even when it does fail due to the
li
element count, it does not retry for 5 seconds, but only for 50-100ms because that's when the exception arrives.If I try to use
expect
to fail the test if fails the assertion, but proceedsExpected
The test fails if the
pageerror
callback throws an errorActual
[Describe actual behavior]
The text was updated successfully, but these errors were encountered: