Skip to content

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.

test: unflake 'should handle failed snapshots due to dialog' test (#37282)

Max Schmitt8036df3735fe
diff --git a/tests/library/trace-viewer.spec.ts b/tests/library/trace-viewer.spec.ts
index 47fc325b28..2b8a3376e6 100644
--- a/tests/library/trace-viewer.spec.ts
+++ b/tests/library/trace-viewer.spec.ts
@@ -1980,36 +1980,43 @@ test('should show all actions', async ({ runAndTrace, page }) => {
]);
});
-test('should handle failed snapshots due to dialog', async ({ page, server, runAndTrace }) => {
- const traceViewer = await runAndTrace(async () => {
- await page.setContent(`
- <head>
- <style>
- button { color: red; }
- </style>
- </head>
- <body>
- <button>Click me</button>
- <script>
- const button = document.querySelector('button');
- window.history.pushState({ page: 'stay' }, '', window.location.href);
- window.addEventListener('popstate', () => {
- if (window.confirm('ready?'))
- button.textContent = 'Clicked';
- });
- </script>
- </body>
- `);
- let dialogMessage = '';
- page.on('dialog', async dialog => {
- dialogMessage = dialog.message();
- await dialog.accept();
+test.describe(() => {
+ // NOTE: In Firefox/WebKit, history.pushState() requires a SecureContext.
+ // On http/about:blank it throws "The operation is insecure".
+ test.use({ ignoreHTTPSErrors: true });
+
+ test('should handle failed snapshots due to dialog', async ({ page, httpsServer, runAndTrace }) => {
+ const traceViewer = await runAndTrace(async () => {
+ await page.goto(httpsServer.EMPTY_PAGE);
+ await page.setContent(`
+ <head>
+ <style>
+ button { color: red; }
+ </style>
+ </head>
+ <body>
+ <button>Click me</button>
+ <script>
+ const button = document.querySelector('button');
+ window.history.pushState({ page: 'stay' }, '', window.location.href);
+ window.addEventListener('popstate', () => {
+ if (window.confirm('ready?'))
+ button.textContent = 'Clicked';
+ });
+ </script>
+ </body>
+ `);
+ let dialogMessage = '';
+ page.on('dialog', async dialog => {
+ dialogMessage = dialog.message();
+ await dialog.accept();
+ });
+ await page.goBack();
+ await expect.poll(() => dialogMessage).toBe('ready?');
+ await expect(page.getByRole('button')).toHaveText('Clicked');
});
- await page.goBack();
- await expect.poll(() => dialogMessage).toBe('ready?');
- await expect(page.getByRole('button')).toHaveText('Clicked');
- });
- const frame = await traceViewer.snapshotFrame('Expect');
- await expect(frame.getByRole('button')).toHaveCSS('color', 'rgb(255, 0, 0)');
+ const frame = await traceViewer.snapshotFrame('Expect');
+ await expect(frame.getByRole('button')).toHaveCSS('color', 'rgb(255, 0, 0)');
+ });
});