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 some network-tab related tests (#35574)

Dmitry Gozman51a7b8f27f67
diff --git a/tests/assets/network-tab/network.html b/tests/assets/network-tab/network.html
index c5b5038e08..2544a7bf9d 100644
--- a/tests/assets/network-tab/network.html
+++ b/tests/assets/network-tab/network.html
@@ -12,8 +12,6 @@
}
</style>
<script src='script.js'></script>
- <script>fetch('/api/endpoint')</script>
- <script>fetch('/call-with-query-params?param1=value1&param1=value2&param2=value2')</script>
<script>
const body = JSON.stringify({
data: {
@@ -21,17 +19,25 @@
array: ['value-1', 'value-2'],
},
});
+ const fetches = [
+ fetch('/api/endpoint'),
+ fetch('/call-with-query-params?param1=value1&param1=value2&param2=value2'),
+ fetch('/post-data-1', {
+ method: 'POST',
+ headers: { 'content-type': 'application/json' },
+ body,
+ }),
+ fetch('/post-data-2', {
+ method: 'POST',
+ headers: { 'Content-Type': 'application/json' },
+ body,
+ }),
+ ];
+ window.donePromise = Promise.all(fetches.map(f => f.then(r => r.body()).then(() => null).catch(e => {})));
+ </script>
+ <script></script>
+ <script>
- fetch('/post-data-1', {
- method: 'POST',
- headers: { 'content-type': 'application/json' },
- body,
- });
- fetch('/post-data-2', {
- method: 'POST',
- headers: { 'Content-Type': 'application/json' },
- body,
- });
</script>
</head>
<body>
diff --git a/tests/library/trace-viewer.spec.ts b/tests/library/trace-viewer.spec.ts
index 45813944d2..5e795b8913 100644
--- a/tests/library/trace-viewer.spec.ts
+++ b/tests/library/trace-viewer.spec.ts
@@ -367,6 +367,7 @@ test('should filter network requests by resource type', async ({ page, runAndTra
const traceViewer = await runAndTrace(async () => {
server.setRoute('/api/endpoint', (_, res) => res.setHeader('Content-Type', 'application/json').end());
await page.goto(`${server.PREFIX}/network-tab/network.html`);
+ await page.evaluate(() => (window as any).donePromise);
});
await traceViewer.selectAction('http://localhost');
await traceViewer.showNetworkTab();
@@ -399,6 +400,7 @@ test('should filter network requests by resource type', async ({ page, runAndTra
test('should show font preview', async ({ page, runAndTrace, server }) => {
const traceViewer = await runAndTrace(async () => {
await page.goto(`${server.PREFIX}/network-tab/network.html`);
+ await page.evaluate(() => (window as any).donePromise);
});
await traceViewer.selectAction('http://localhost');
await traceViewer.showNetworkTab();
@@ -413,6 +415,7 @@ test('should show font preview', async ({ page, runAndTrace, server }) => {
test('should filter network requests by url', async ({ page, runAndTrace, server }) => {
const traceViewer = await runAndTrace(async () => {
await page.goto(`${server.PREFIX}/network-tab/network.html`);
+ await page.evaluate(() => (window as any).donePromise);
});
await traceViewer.selectAction('http://localhost');
await traceViewer.showNetworkTab();
diff --git a/tests/playwright-test/ui-mode-test-network-tab.spec.ts b/tests/playwright-test/ui-mode-test-network-tab.spec.ts
index 6905dec505..15896a2064 100644
--- a/tests/playwright-test/ui-mode-test-network-tab.spec.ts
+++ b/tests/playwright-test/ui-mode-test-network-tab.spec.ts
@@ -24,6 +24,7 @@ test('should filter network requests by resource type', async ({ runUITest, serv
import { test, expect } from '@playwright/test';
test('network tab test', async ({ page }) => {
await page.goto('${server.PREFIX}/network-tab/network.html');
+ await page.evaluate(() => (window as any).donePromise);
});
`,
});
@@ -64,6 +65,7 @@ test('should filter network requests by url', async ({ runUITest, server }) => {
import { test, expect } from '@playwright/test';
test('network tab test', async ({ page }) => {
await page.goto('${server.PREFIX}/network-tab/network.html');
+ await page.evaluate(() => (window as any).donePromise);
});
`,
});
@@ -100,6 +102,7 @@ test('should format JSON request body', async ({ runUITest, server }) => {
import { test, expect } from '@playwright/test';
test('network tab test', async ({ page }) => {
await page.goto('${server.PREFIX}/network-tab/network.html');
+ await page.evaluate(() => (window as any).donePromise);
});
`,
});
@@ -142,6 +145,7 @@ test('should display list of query parameters (only if present)', async ({ runUI
import { test, expect } from '@playwright/test';
test('network tab test', async ({ page }) => {
await page.goto('${server.PREFIX}/network-tab/network.html');
+ await page.evaluate(() => (window as any).donePromise);
});
`,
});