Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
TypeScript automationchromechromiume2e-testingelectronend-to-end-testingfirefoxjavascriptplaywrighttesttest-automationtestingtesting-toolswebwebkit
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.htmlindex 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¶m1=value2¶m2=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¶m1=value2¶m2=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.tsindex 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, runAndTraconst 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, runAndTratest('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.tsindex 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, servimport { 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 ({ runUIimport { 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);});`,});