Skip to content
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

feat: add support for browserContext.on('pageerror') #24452

Merged
merged 7 commits into from
Aug 17, 2023

Conversation

vigneshshanmugam
Copy link
Contributor

@vigneshshanmugam vigneshshanmugam commented Jul 27, 2023

@vigneshshanmugam
Copy link
Contributor Author

@dgozman Thoughts? I am still trying to fix the docs and tests.

@github-actions
Copy link
Contributor

Test results for "tests 1"

12 failed
❌ [chromium-ubuntu-22.04-node16] › library/browsercontext-pageerror-event.spec.ts:21:3 › should receive pageError in context
❌ [chromium-ubuntu-22.04-node16] › page/workers.spec.ts:90:3 › should report errors
❌ [webkit-ubuntu-22.04-node16] › library/browsercontext-pageerror-event.spec.ts:21:3 › should receive pageError in context
❌ [webkit-ubuntu-22.04-node16] › page/workers.spec.ts:90:3 › should report errors
❌ [chromium-ubuntu-20.04-chromium-tip-of-tree] › library/browsercontext-pageerror-event.spec.ts:21:3 › should receive pageError in context
❌ [chromium-ubuntu-20.04-chromium-tip-of-tree] › page/workers.spec.ts:90:3 › should report errors
❌ [chromium-ubuntu-22.04-node20] › library/browsercontext-pageerror-event.spec.ts:21:3 › should receive pageError in context
❌ [chromium-ubuntu-22.04-node20] › page/workers.spec.ts:90:3 › should report errors
❌ [chromium-ubuntu-22.04-node18] › library/browsercontext-pageerror-event.spec.ts:21:3 › should receive pageError in context
❌ [chromium-ubuntu-22.04-node18] › page/workers.spec.ts:90:3 › should report errors
❌ [firefox-ubuntu-22.04-node16] › library/browsercontext-pageerror-event.spec.ts:21:3 › should receive pageError in context
❌ [firefox-ubuntu-22.04-node16] › page/workers.spec.ts:90:3 › should report errors

7 flaky
⚠️ [chromium-ubuntu-22.04-node16] › page/page-event-request.spec.ts:129:3 › should report navigation requests and responses handled by service worker with routing
⚠️ [webkit-ubuntu-22.04-node16] › library/inspector/cli-codegen-pytest.spec.ts:56:5 › should save the codegen output to a file if specified
⚠️ [chromium-ubuntu-22.04-node20] › library/tracing.spec.ts:239:5 › should not include trace resources from the previous chunks
⚠️ [chromium-ubuntu-22.04-node20] › page/page-event-request.spec.ts:129:3 › should report navigation requests and responses handled by service worker with routing
⚠️ [playwright-test-ubuntu-latest-node16] › ui-mode-test-update.spec.ts:172:5 › should update test locations
⚠️ [playwright-test-macos-latest-node16] › ui-mode-trace.spec.ts:126:5 › should show snapshots for sync assertions
⚠️ [playwright-test-windows-latest-node16] › ui-mode-test-progress.spec.ts:218:5 › should show trace w/ multiple contexts

24943 passed, 583 skipped
✔️✔️✔️

[chromium-ubuntu-22.04-node16] › library/browsercontext-pageerror-event.spec.ts:21:3 › should receive pageError in context

Error: expect(received).toBe(expected) // Object.is equality

Expected: 1
Received: 0

  29 |   ]);
  30 |   console.log('messages', messages);
> 31 |   expect(messages.length).toBe(1);
     |                           ^
  32 | });
  33 |

    at /home/runner/work/playwright/playwright/tests/library/browsercontext-pageerror-event.spec.ts:31:27

Retry 1:

Error: expect(received).toBe(expected) // Object.is equality

Expected: 1
Received: 0

  29 |   ]);
  30 |   console.log('messages', messages);
> 31 |   expect(messages.length).toBe(1);
     |                           ^
  32 | });
  33 |

    at /home/runner/work/playwright/playwright/tests/library/browsercontext-pageerror-event.spec.ts:31:27

Retry 2:

Error: expect(received).toBe(expected) // Object.is equality

Expected: 1
Received: 0

  29 |   ]);
  30 |   console.log('messages', messages);
> 31 |   expect(messages.length).toBe(1);
     |                           ^
  32 | });
  33 |

    at /home/runner/work/playwright/playwright/tests/library/browsercontext-pageerror-event.spec.ts:31:27

Retry 3:

Error: expect(received).toBe(expected) // Object.is equality

Expected: 1
Received: 0

  29 |   ]);
  30 |   console.log('messages', messages);
> 31 |   expect(messages.length).toBe(1);
     |                           ^
  32 | });
  33 |

    at /home/runner/work/playwright/playwright/tests/library/browsercontext-pageerror-event.spec.ts:31:27

[chromium-ubuntu-22.04-node16] › page/workers.spec.ts:90:3 › should report errors

Test timeout of 30000ms exceeded.

Retry 1:

Test timeout of 30000ms exceeded.

Retry 2:

Test timeout of 30000ms exceeded.

Retry 3:

Test timeout of 30000ms exceeded.

[webkit-ubuntu-22.04-node16] › library/browsercontext-pageerror-event.spec.ts:21:3 › should receive pageError in context

Error: expect(received).toBe(expected) // Object.is equality

Expected: 1
Received: 0

  29 |   ]);
  30 |   console.log('messages', messages);
> 31 |   expect(messages.length).toBe(1);
     |                           ^
  32 | });
  33 |

    at /home/runner/work/playwright/playwright/tests/library/browsercontext-pageerror-event.spec.ts:31:27

Retry 1:

Error: expect(received).toBe(expected) // Object.is equality

Expected: 1
Received: 0

  29 |   ]);
  30 |   console.log('messages', messages);
> 31 |   expect(messages.length).toBe(1);
     |                           ^
  32 | });
  33 |

    at /home/runner/work/playwright/playwright/tests/library/browsercontext-pageerror-event.spec.ts:31:27

Retry 2:

Error: expect(received).toBe(expected) // Object.is equality

Expected: 1
Received: 0

  29 |   ]);
  30 |   console.log('messages', messages);
> 31 |   expect(messages.length).toBe(1);
     |                           ^
  32 | });
  33 |

    at /home/runner/work/playwright/playwright/tests/library/browsercontext-pageerror-event.spec.ts:31:27

Retry 3:

Error: expect(received).toBe(expected) // Object.is equality

Expected: 1
Received: 0

  29 |   ]);
  30 |   console.log('messages', messages);
> 31 |   expect(messages.length).toBe(1);
     |                           ^
  32 | });
  33 |

    at /home/runner/work/playwright/playwright/tests/library/browsercontext-pageerror-event.spec.ts:31:27

[webkit-ubuntu-22.04-node16] › page/workers.spec.ts:90:3 › should report errors

Test timeout of 30000ms exceeded.

Retry 1:

Test timeout of 30000ms exceeded.

Retry 2:

Test timeout of 30000ms exceeded.

Retry 3:

Test timeout of 30000ms exceeded.

[chromium-ubuntu-20.04-chromium-tip-of-tree] › library/browsercontext-pageerror-event.spec.ts:21:3 › should receive pageError in context

Error: expect(received).toBe(expected) // Object.is equality

Expected: 1
Received: 0

  29 |   ]);
  30 |   console.log('messages', messages);
> 31 |   expect(messages.length).toBe(1);
     |                           ^
  32 | });
  33 |

    at /home/runner/work/playwright/playwright/tests/library/browsercontext-pageerror-event.spec.ts:31:27

Retry 1:

Error: expect(received).toBe(expected) // Object.is equality

Expected: 1
Received: 0

  29 |   ]);
  30 |   console.log('messages', messages);
> 31 |   expect(messages.length).toBe(1);
     |                           ^
  32 | });
  33 |

    at /home/runner/work/playwright/playwright/tests/library/browsercontext-pageerror-event.spec.ts:31:27

Retry 2:

Error: expect(received).toBe(expected) // Object.is equality

Expected: 1
Received: 0

  29 |   ]);
  30 |   console.log('messages', messages);
> 31 |   expect(messages.length).toBe(1);
     |                           ^
  32 | });
  33 |

    at /home/runner/work/playwright/playwright/tests/library/browsercontext-pageerror-event.spec.ts:31:27

Retry 3:

Error: expect(received).toBe(expected) // Object.is equality

Expected: 1
Received: 0

  29 |   ]);
  30 |   console.log('messages', messages);
> 31 |   expect(messages.length).toBe(1);
     |                           ^
  32 | });
  33 |

    at /home/runner/work/playwright/playwright/tests/library/browsercontext-pageerror-event.spec.ts:31:27

[chromium-ubuntu-20.04-chromium-tip-of-tree] › page/workers.spec.ts:90:3 › should report errors

Test timeout of 30000ms exceeded.

Retry 1:

Test timeout of 30000ms exceeded.

Retry 2:

Test timeout of 30000ms exceeded.

Retry 3:

Test timeout of 30000ms exceeded.

[chromium-ubuntu-22.04-node20] › library/browsercontext-pageerror-event.spec.ts:21:3 › should receive pageError in context

Error: expect(received).toBe(expected) // Object.is equality

Expected: 1
Received: 0

  29 |   ]);
  30 |   console.log('messages', messages);
> 31 |   expect(messages.length).toBe(1);
     |                           ^
  32 | });
  33 |

    at /home/runner/work/playwright/playwright/tests/library/browsercontext-pageerror-event.spec.ts:31:27

Retry 1:

Error: expect(received).toBe(expected) // Object.is equality

Expected: 1
Received: 0

  29 |   ]);
  30 |   console.log('messages', messages);
> 31 |   expect(messages.length).toBe(1);
     |                           ^
  32 | });
  33 |

    at /home/runner/work/playwright/playwright/tests/library/browsercontext-pageerror-event.spec.ts:31:27

Retry 2:

Error: expect(received).toBe(expected) // Object.is equality

Expected: 1
Received: 0

  29 |   ]);
  30 |   console.log('messages', messages);
> 31 |   expect(messages.length).toBe(1);
     |                           ^
  32 | });
  33 |

    at /home/runner/work/playwright/playwright/tests/library/browsercontext-pageerror-event.spec.ts:31:27

Retry 3:

Error: expect(received).toBe(expected) // Object.is equality

Expected: 1
Received: 0

  29 |   ]);
  30 |   console.log('messages', messages);
> 31 |   expect(messages.length).toBe(1);
     |                           ^
  32 | });
  33 |

    at /home/runner/work/playwright/playwright/tests/library/browsercontext-pageerror-event.spec.ts:31:27

[chromium-ubuntu-22.04-node20] › page/workers.spec.ts:90:3 › should report errors

Test timeout of 30000ms exceeded.

Retry 1:

Test timeout of 30000ms exceeded.

Retry 2:

Test timeout of 30000ms exceeded.

Retry 3:

Test timeout of 30000ms exceeded.

[chromium-ubuntu-22.04-node18] › library/browsercontext-pageerror-event.spec.ts:21:3 › should receive pageError in context

Error: expect(received).toBe(expected) // Object.is equality

Expected: 1
Received: 0

  29 |   ]);
  30 |   console.log('messages', messages);
> 31 |   expect(messages.length).toBe(1);
     |                           ^
  32 | });
  33 |

    at /home/runner/work/playwright/playwright/tests/library/browsercontext-pageerror-event.spec.ts:31:27

Retry 1:

Error: expect(received).toBe(expected) // Object.is equality

Expected: 1
Received: 0

  29 |   ]);
  30 |   console.log('messages', messages);
> 31 |   expect(messages.length).toBe(1);
     |                           ^
  32 | });
  33 |

    at /home/runner/work/playwright/playwright/tests/library/browsercontext-pageerror-event.spec.ts:31:27

Retry 2:

Error: expect(received).toBe(expected) // Object.is equality

Expected: 1
Received: 0

  29 |   ]);
  30 |   console.log('messages', messages);
> 31 |   expect(messages.length).toBe(1);
     |                           ^
  32 | });
  33 |

    at /home/runner/work/playwright/playwright/tests/library/browsercontext-pageerror-event.spec.ts:31:27

Retry 3:

Error: expect(received).toBe(expected) // Object.is equality

Expected: 1
Received: 0

  29 |   ]);
  30 |   console.log('messages', messages);
> 31 |   expect(messages.length).toBe(1);
     |                           ^
  32 | });
  33 |

    at /home/runner/work/playwright/playwright/tests/library/browsercontext-pageerror-event.spec.ts:31:27

[chromium-ubuntu-22.04-node18] › page/workers.spec.ts:90:3 › should report errors

Test timeout of 30000ms exceeded.

Retry 1:

Test timeout of 30000ms exceeded.

Retry 2:

Test timeout of 30000ms exceeded.

Retry 3:

Test timeout of 30000ms exceeded.

[firefox-ubuntu-22.04-node16] › library/browsercontext-pageerror-event.spec.ts:21:3 › should receive pageError in context

Error: expect(received).toBe(expected) // Object.is equality

Expected: 1
Received: 0

  29 |   ]);
  30 |   console.log('messages', messages);
> 31 |   expect(messages.length).toBe(1);
     |                           ^
  32 | });
  33 |

    at /home/runner/work/playwright/playwright/tests/library/browsercontext-pageerror-event.spec.ts:31:27

Retry 1:

Error: expect(received).toBe(expected) // Object.is equality

Expected: 1
Received: 0

  29 |   ]);
  30 |   console.log('messages', messages);
> 31 |   expect(messages.length).toBe(1);
     |                           ^
  32 | });
  33 |

    at /home/runner/work/playwright/playwright/tests/library/browsercontext-pageerror-event.spec.ts:31:27

Retry 2:

Error: expect(received).toBe(expected) // Object.is equality

Expected: 1
Received: 0

  29 |   ]);
  30 |   console.log('messages', messages);
> 31 |   expect(messages.length).toBe(1);
     |                           ^
  32 | });
  33 |

    at /home/runner/work/playwright/playwright/tests/library/browsercontext-pageerror-event.spec.ts:31:27

Retry 3:

Error: expect(received).toBe(expected) // Object.is equality

Expected: 1
Received: 0

  29 |   ]);
  30 |   console.log('messages', messages);
> 31 |   expect(messages.length).toBe(1);
     |                           ^
  32 | });
  33 |

    at /home/runner/work/playwright/playwright/tests/library/browsercontext-pageerror-event.spec.ts:31:27

[firefox-ubuntu-22.04-node16] › page/workers.spec.ts:90:3 › should report errors

Test timeout of 30000ms exceeded.

Retry 1:

Test timeout of 30000ms exceeded.

Retry 2:

Test timeout of 30000ms exceeded.

Retry 3:

Test timeout of 30000ms exceeded.

Merge workflow run.

@dgozman
Copy link
Contributor

dgozman commented Jul 27, 2023

@dgozman Thoughts? I am still trying to fix the docs and tests.

We considered this, but so far there is no way to get the Page object from the Error, so that one can know from which page a particular error has originated. Without page attribution, we would need a very strong reason to expose this event. Would you mind filing an issue with the usecase and linking this PR to it?

@vigneshshanmugam
Copy link
Contributor Author

We considered this, but so far there is no way to get the Page object from the Error, so that one can know from which page a particular error has originated.

Ahh didn't know that was not possible. Would it be possible to arbitrary fetch the currentPage the context is on and also report that along with it?. Created a feature request #24466

@vigneshshanmugam vigneshshanmugam marked this pull request as ready for review July 27, 2023 22:25
@github-actions
Copy link
Contributor

Test results for "tests 1"

7 failed
❌ [chromium-ubuntu-22.04-node20] › page/workers.spec.ts:90:3 › should report errors
❌ [chromium-ubuntu-20.04-chromium-tip-of-tree] › page/workers.spec.ts:90:3 › should report errors
❌ [chromium-ubuntu-22.04-node18] › page/workers.spec.ts:90:3 › should report errors
❌ [chromium-ubuntu-22.04-node16] › page/workers.spec.ts:90:3 › should report errors
❌ [webkit-ubuntu-22.04-node16] › page/workers.spec.ts:90:3 › should report errors
❌ [firefox-ubuntu-22.04-node16] › page/workers.spec.ts:90:3 › should report errors
❌ [playwright-test-windows-latest-node16] › reporter-html.spec.ts:1452:7 › merged › labels › filter should update stats

6 flaky
⚠️ [chromium-ubuntu-22.04-node20] › library/tracing.spec.ts:239:5 › should not include trace resources from the previous chunks
⚠️ [chromium-ubuntu-22.04-node18] › library/tracing.spec.ts:239:5 › should not include trace resources from the previous chunks
⚠️ [webkit-ubuntu-22.04-node16] › library/browsercontext-fetch.spec.ts:1039:3 › should abort requests when browser context closes
⚠️ [webkit-ubuntu-22.04-node16] › library/inspector/cli-codegen-pytest.spec.ts:56:5 › should save the codegen output to a file if specified
⚠️ [playwright-test-windows-latest-node16] › ui-mode-test-progress.spec.ts:167:5 › should update tracing network live
⚠️ [playwright-test-windows-latest-node16] › ui-mode-trace.spec.ts:53:5 › should merge web assertion events

25009 passed, 583 skipped
✔️✔️✔️

[chromium-ubuntu-22.04-node20] › page/workers.spec.ts:90:3 › should report errors

Test timeout of 30000ms exceeded.

Retry 1:

Test timeout of 30000ms exceeded.

Retry 2:

Test timeout of 30000ms exceeded.

Retry 3:

Test timeout of 30000ms exceeded.

[chromium-ubuntu-20.04-chromium-tip-of-tree] › page/workers.spec.ts:90:3 › should report errors

Test timeout of 30000ms exceeded.

Retry 1:

Test timeout of 30000ms exceeded.

Retry 2:

Test timeout of 30000ms exceeded.

Retry 3:

Test timeout of 30000ms exceeded.

[chromium-ubuntu-22.04-node18] › page/workers.spec.ts:90:3 › should report errors

Test timeout of 30000ms exceeded.

Retry 1:

Test timeout of 30000ms exceeded.

Retry 2:

Test timeout of 30000ms exceeded.

Retry 3:

Test timeout of 30000ms exceeded.

[chromium-ubuntu-22.04-node16] › page/workers.spec.ts:90:3 › should report errors

Test timeout of 30000ms exceeded.

Retry 1:

Test timeout of 30000ms exceeded.

Retry 2:

Test timeout of 30000ms exceeded.

Retry 3:

Test timeout of 30000ms exceeded.

[webkit-ubuntu-22.04-node16] › page/workers.spec.ts:90:3 › should report errors

Test timeout of 30000ms exceeded.

Retry 1:

Test timeout of 30000ms exceeded.

Retry 2:

Test timeout of 30000ms exceeded.

Retry 3:

Test timeout of 30000ms exceeded.

[firefox-ubuntu-22.04-node16] › page/workers.spec.ts:90:3 › should report errors

Test timeout of 30000ms exceeded.

Retry 1:

Test timeout of 30000ms exceeded.

Retry 2:

Test timeout of 30000ms exceeded.

Retry 3:

Test timeout of 30000ms exceeded.

[playwright-test-windows-latest-node16] › reporter-html.spec.ts:1452:7 › merged › labels › filter should update stats

Error: expect(received).toBe(expected) // Object.is equality

Expected: "Total time: 1129ms"
Received: "Total time: 1.1s"

  1774 |         await expect(page.locator('.chip', { hasText: 'c.test.js' })).toHaveCount(1);
  1775 |
> 1776 |         await flakyButton.click();
       |                                 ^
  1777 |
  1778 |         await expect(searchInput).toHaveValue('@regression @flaky');
  1779 |         await expect(page).toHaveURL(/@regression%20@flaky/);

    at checkTotalDuration (D:\a\playwright\playwright\tests\playwright-test\reporter-html.spec.ts:1776:33)
    at D:\a\playwright\playwright\tests\playwright-test\reporter-html.spec.ts:1792:9

Merge workflow run.

packages/protocol/src/protocol.yml Outdated Show resolved Hide resolved
tests/library/browsercontext-pageerror-event.spec.ts Outdated Show resolved Hide resolved
packages/playwright-core/src/client/browserContext.ts Outdated Show resolved Hide resolved
@github-actions
Copy link
Contributor

github-actions bot commented Aug 1, 2023

Test results for "tests 1"

4 interrupted
⚠️ [playwright-test-windows-latest-node16] › expect-poll.spec.ts:140:5 › should not retry predicate that threw an error
⚠️ [playwright-test-windows-latest-node16] › expect-to-pass.spec.ts:80:5 › should support .not predicate
⚠️ [playwright-test-windows-latest-node16] › reporter-html.spec.ts:1056:7 › merged › labels › should show labels in the test row
⚠️ [playwright-test-windows-latest-node16] › reporter-html.spec.ts:1158:7 › merged › labels › project label still shows up without test labels

241 passed, 980 skipped
✔️✔️✔️

Merge workflow run.

@github-actions
Copy link
Contributor

github-actions bot commented Aug 1, 2023

Test results for "tests 1"

4 interrupted
⚠️ [playwright-test-windows-latest-node16] › esm.spec.ts:481:5 › should resolve .js import to .tsx file in ESM mode for components
⚠️ [playwright-test-windows-latest-node16] › expect-configure.spec.ts:91:5 › should chain configure
⚠️ [playwright-test-windows-latest-node16] › reporter-html.spec.ts:337:5 › merged › should use different path if attachments base url option is provided
⚠️ [playwright-test-windows-latest-node16] › reporter-html.spec.ts:373:5 › merged › should include stdio

197 passed, 1024 skipped
✔️✔️✔️

Merge workflow run.

@github-actions
Copy link
Contributor

github-actions bot commented Aug 1, 2023

Test results for "tests 1"

1 failed
❌ [webkit-ubuntu-22.04-node16] › library/browsercontext-events.spec.ts:164:5 › pageError event should work

5 flaky
⚠️ [webkit-ubuntu-22.04-node16] › library/browsercontext-fetch.spec.ts:1039:3 › should abort requests when browser context closes
⚠️ [webkit-ubuntu-22.04-node16] › library/browsercontext-reuse.spec.ts:50:1 › should reset serviceworker
⚠️ [chromium-ubuntu-22.04-node18] › library/tracing.spec.ts:239:5 › should not include trace resources from the previous chunks
⚠️ [firefox-ubuntu-22.04-node16] › page/page-goto.spec.ts:81:3 › should work with Cross-Origin-Opener-Policy
⚠️ [chromium-ubuntu-20.04-chromium-tip-of-tree] › library/tracing.spec.ts:469:5 › should work with multiple chunks

25033 passed, 583 skipped
✔️✔️✔️

[webkit-ubuntu-22.04-node16] › library/browsercontext-events.spec.ts:164:5 › pageError event should work

Error: expect(received).toContain(expected) // indexOf

Expected substring: "myscript.js"
Received string:    "Error: Fancy error!
    at c (http://localhost:8911/error.html:14:36)
    at b (http://localhost:8911/error.html:10:6)
    at a (http://localhost:8911/error.html:6:6)
    at global code (http://localhost:8911/error.html:3:2)"

  168 |   ]);
  169 |   expect(pageerror.page()).toBe(page);
> 170 |   expect(pageerror.error().stack).toContain('myscript.js');
      |                                   ^
  171 | });
  172 |

    at /home/runner/work/playwright/playwright/tests/library/browsercontext-events.spec.ts:170:35

Retry 1:

Error: expect(received).toContain(expected) // indexOf

Expected substring: "myscript.js"
Received string:    "Error: Fancy error!
    at c (http://localhost:8915/error.html:14:36)
    at b (http://localhost:8915/error.html:10:6)
    at a (http://localhost:8915/error.html:6:6)
    at global code (http://localhost:8915/error.html:3:2)"

  168 |   ]);
  169 |   expect(pageerror.page()).toBe(page);
> 170 |   expect(pageerror.error().stack).toContain('myscript.js');
      |                                   ^
  171 | });
  172 |

    at /home/runner/work/playwright/playwright/tests/library/browsercontext-events.spec.ts:170:35

Retry 2:

Error: expect(received).toContain(expected) // indexOf

Expected substring: "myscript.js"
Received string:    "Error: Fancy error!
    at c (http://localhost:8919/error.html:14:36)
    at b (http://localhost:8919/error.html:10:6)
    at a (http://localhost:8919/error.html:6:6)
    at global code (http://localhost:8919/error.html:3:2)"

  168 |   ]);
  169 |   expect(pageerror.page()).toBe(page);
> 170 |   expect(pageerror.error().stack).toContain('myscript.js');
      |                                   ^
  171 | });
  172 |

    at /home/runner/work/playwright/playwright/tests/library/browsercontext-events.spec.ts:170:35

Retry 3:

Error: expect(received).toContain(expected) // indexOf

Expected substring: "myscript.js"
Received string:    "Error: Fancy error!
    at c (http://localhost:8923/error.html:14:36)
    at b (http://localhost:8923/error.html:10:6)
    at a (http://localhost:8923/error.html:6:6)
    at global code (http://localhost:8923/error.html:3:2)"

  168 |   ]);
  169 |   expect(pageerror.page()).toBe(page);
> 170 |   expect(pageerror.error().stack).toContain('myscript.js');
      |                                   ^
  171 | });
  172 |

    at /home/runner/work/playwright/playwright/tests/library/browsercontext-events.spec.ts:170:35

Merge workflow run.

docs/src/api/class-pageerror.md Show resolved Hide resolved
packages/playwright-core/src/client/page.ts Outdated Show resolved Hide resolved
utils/doclint/missingDocs.js Outdated Show resolved Hide resolved
packages/playwright-core/src/server/fetch.ts Outdated Show resolved Hide resolved
@github-actions
Copy link
Contributor

github-actions bot commented Aug 1, 2023

Test results for "tests 1"

1 failed
❌ [playwright-test-macos-latest-node16] › expect-poll.spec.ts:222:5 › should show intermediate result for poll that spills over test time

10 flaky
⚠️ [webkit-ubuntu-22.04-node16] › library/browsercontext-fetch.spec.ts:1039:3 › should abort requests when browser context closes
⚠️ [webkit-ubuntu-22.04-node16] › library/browsercontext-reuse.spec.ts:50:1 › should reset serviceworker
⚠️ [webkit-ubuntu-22.04-node16] › library/inspector/cli-codegen-python.spec.ts:74:5 › should save the codegen output to a file if specified
⚠️ [chromium-ubuntu-22.04-node16] › page/page-event-request.spec.ts:130:3 › should report navigation requests and responses handled by service worker with routing
⚠️ [chromium-ubuntu-20.04-chromium-tip-of-tree] › library/inspector/cli-codegen-javascript.spec.ts:87:5 › should save the codegen output to a file if specified
⚠️ [chromium-ubuntu-22.04-node20] › library/tracing.spec.ts:239:5 › should not include trace resources from the previous chunks
⚠️ [playwright-test-macos-latest-node16] › ui-mode-trace.spec.ts:22:5 › should merge trace events
⚠️ [playwright-test-macos-latest-node16] › ui-mode-trace.spec.ts:53:5 › should merge web assertion events
⚠️ [playwright-test-ubuntu-latest-node20] › ui-mode-trace.spec.ts:126:5 › should show snapshots for sync assertions
⚠️ [playwright-test-windows-latest-node16] › ui-mode-test-progress.spec.ts:218:5 › should show trace w/ multiple contexts

25028 passed, 583 skipped
✔️✔️✔️

[playwright-test-macos-latest-node16] › expect-poll.spec.ts:222:5 › should show intermediate result for poll that spills over test time

Error: expect(received).toContain(expected) // indexOf

Expected substring: "Expected: 2"
Received string:    "
Running 1 test using 1 worker·
  ✘  1 a.spec.ts:3:11 › should fail (2.0s)··
  1) a.spec.ts:3:11 › should fail ──────────────────────────────────────────────────────────────────·
    Test timeout of 2000ms exceeded.·
  1 failed
    a.spec.ts:3:11 › should fail ───────────────────────────────────────────────────────────────────
"

  230 |   }, { timeout: 2000 });
  231 |   expect(result.exitCode).toBe(1);
> 232 |   expect(result.output).toContain('Expected: 2');
      |                         ^
  233 |   expect(result.output).toContain('Received: 3');
  234 | });
  235 |

    at /Users/runner/work/playwright/playwright/tests/playwright-test/expect-poll.spec.ts:232:25

Merge workflow run.

Copy link
Contributor

@dgozman dgozman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks very good, just a few comments.

I think we should leave page as non-nullable in the protocol.yml and as nullable in the api, like you already have.

packages/playwright-core/src/client/api.ts Outdated Show resolved Hide resolved
packages/playwright-core/src/server/chromium/crPage.ts Outdated Show resolved Hide resolved
packages/playwright-core/src/client/browserContext.ts Outdated Show resolved Hide resolved
@github-actions
Copy link
Contributor

github-actions bot commented Aug 2, 2023

Test results for "tests 1"

1 failed
❌ [playwright-test-windows-latest-node16] › reporter-html.spec.ts:1452:7 › merged › labels › filter should update stats

6 flaky
⚠️ [webkit-ubuntu-22.04-node16] › library/inspector/cli-codegen-javascript.spec.ts:87:5 › should save the codegen output to a file if specified
⚠️ [chromium-ubuntu-22.04-node16] › library/tracing.spec.ts:239:5 › should not include trace resources from the previous chunks
⚠️ [playwright-test-windows-latest-node16] › ui-mode-test-progress.spec.ts:218:5 › should show trace w/ multiple contexts
⚠️ [playwright-test-windows-latest-node16] › ui-mode-trace.spec.ts:53:5 › should merge web assertion events
⚠️ [playwright-test-ubuntu-latest-node20] › ui-mode-test-progress.spec.ts:167:5 › should update tracing network live
⚠️ [playwright-test-macos-latest-node16] › ui-mode-trace.spec.ts:126:5 › should show snapshots for sync assertions

25037 passed, 583 skipped
✔️✔️✔️

[playwright-test-windows-latest-node16] › reporter-html.spec.ts:1452:7 › merged › labels › filter should update stats

Error: expect(received).toBe(expected) // Object.is equality

Expected: "Total time: 1157ms"
Received: "Total time: 1.2s"

  1774 |         await expect(page.locator('.chip', { hasText: 'c.test.js' })).toHaveCount(1);
  1775 |
> 1776 |         await flakyButton.click();
       |                                 ^
  1777 |
  1778 |         await expect(searchInput).toHaveValue('@regression @flaky');
  1779 |         await expect(page).toHaveURL(/@regression%20@flaky/);

    at checkTotalDuration (D:\a\playwright\playwright\tests\playwright-test\reporter-html.spec.ts:1776:33)
    at D:\a\playwright\playwright\tests\playwright-test\reporter-html.spec.ts:1792:9

Merge workflow run.

@dgozman
Copy link
Contributor

dgozman commented Aug 4, 2023

@vigneshshanmugam This looks great! This change will go into v1.38, so I will merge it once we cut v1.37.

@vigneshshanmugam
Copy link
Contributor Author

@dgozman :yay Thank you

docs/src/api/class-pageerror.md Outdated Show resolved Hide resolved
docs/src/api/class-pageerror.md Outdated Show resolved Hide resolved
docs/src/api/class-pageerror.md Outdated Show resolved Hide resolved
Co-authored-by: Max Schmitt <max@schmitt.mx>
Signed-off-by: Vignesh Shanmugam <vignesh.shanmugam22@gmail.com>
@github-actions
Copy link
Contributor

Test results for "tests 1"

1 failed
❌ [playwright-test] › reporter-html.spec.ts:1491:7 › created › labels › filter should update stats

9 flaky
⚠️ [chromium] › library/tracing.spec.ts:239:5 › should not include trace resources from the previous chunks
⚠️ [chromium] › library/download.spec.ts:525:5 › download event › should be able to cancel pending downloads
⚠️ [chromium] › library/tracing.spec.ts:239:5 › should not include trace resources from the previous chunks
⚠️ [firefox] › page/page-goto.spec.ts:112:3 › should work with Cross-Origin-Opener-Policy after redirect
⚠️ [playwright-test] › ui-mode-trace.spec.ts:53:5 › should merge web assertion events
⚠️ [chromium] › library/tracing.spec.ts:239:5 › should not include trace resources from the previous chunks
⚠️ [chromium] › page/page-event-request.spec.ts:101:3 › should report navigation requests and responses handled by service worker
⚠️ [playwright-test] › ui-mode-test-progress.spec.ts:167:5 › should update tracing network live
⚠️ [webkit] › library/browsercontext-fetch.spec.ts:1039:3 › should abort requests when browser context closes

25060 passed, 583 skipped
✔️✔️✔️

[playwright-test] › reporter-html.spec.ts:1491:7 › created › labels › filter should update stats

Error: expect(received).toBe(expected) // Object.is equality

Expected: "Total time: 1152ms"
Received: "Total time: 1.2s"

  1817 |         await expect(searchInput).toHaveValue('@regression @flaky');
  1818 |         await expect(page).toHaveURL(/@regression%20@flaky/);
> 1819 |         await expect(page.locator('.chip')).toHaveCount(1);
       |                                 ^
  1820 |         await expect(page.locator('.chip', { hasText: 'a.test.js' })).toHaveCount(0);
  1821 |         await expect(page.locator('.chip', { hasText: 'b.test.js' })).toHaveCount(0);
  1822 |         await expect(page.locator('.chip', { hasText: 'c.test.js' })).toHaveCount(1);

    at checkTotalDuration (D:\a\playwright\playwright\tests\playwright-test\reporter-html.spec.ts:1819:33)
    at D:\a\playwright\playwright\tests\playwright-test\reporter-html.spec.ts:1825:9

Merge workflow run.

const pageObject = Page.from(page);
const parsedError = parseError(error);
this.emit(Events.BrowserContext.PageError, new PageError(pageObject, parsedError));
if (pageObject)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is never null as otherwise Page.from would throw, remove this check.

@yury-s yury-s merged commit adc9b2d into microsoft:main Aug 17, 2023
26 of 28 checks passed
@vigneshshanmugam vigneshshanmugam deleted the emit-pageerror-context branch August 31, 2023 18:22
Germandrummer92 pushed a commit to OctoMind-dev/playwright that referenced this pull request Oct 27, 2023
+ fix microsoft#24466
+ Adds support for exposing the `pageerror` events via `browserContext`
API.
+ Helps with capturing the overall exceptions that are thrown outside of
the the current page and also captures the exceptions happens on other
windows/popups.
+ Keeps the API in sync with `context.on('request)',
context.on('console'), etc..`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature] Expose browserContext.on('pageerror') for capturing exceptions
5 participants