Skip to content

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

fix(har): requestFinished/page-close race (#8518)

Max Schmitt3ea2f209ea73
diff --git a/tests/har.spec.ts b/tests/har.spec.ts
index 0703e2e0a1..678053f86b 100644
--- a/tests/har.spec.ts
+++ b/tests/har.spec.ts
@@ -356,9 +356,9 @@ it('should report the correct request body size when the bodySize is 0', async (
});
it('should report the correct response body size when the bodySize is 0', async ({ contextFactory, server }, testInfo) => {
- server.setRoute('/empty.html', (req, res) => res.end(''));
const { page, getLog } = await pageWithHar(contextFactory, testInfo);
- await page.goto(server.EMPTY_PAGE);
+ const response = await page.goto(server.EMPTY_PAGE);
+ await response.finished();
const log = await getLog();
expect(log.entries[0].response.bodySize).toBe(0);
});
diff --git a/tests/page/page-network-request.spec.ts b/tests/page/page-network-request.spec.ts
index 18e550b5a7..57f7c28db3 100644
--- a/tests/page/page-network-request.spec.ts
+++ b/tests/page/page-network-request.spec.ts
@@ -285,7 +285,7 @@ it('should should set bodySize to 0 if there was no body', async ({page, server,
]);
await (await request.response()).finished();
expect(request.sizes().requestBodySize).toBe(0);
- expect(request.sizes().requestHeadersSize).toBeGreaterThanOrEqual(250);
+ expect(request.sizes().requestHeadersSize).toBeGreaterThanOrEqual(228);
});
it('should should set bodySize, headersSize, and transferSize', async ({page, server, browserName, platform}) => {
@@ -308,18 +308,7 @@ it('should should set bodySize, headersSize, and transferSize', async ({page, se
});
it('should should set bodySize to 0 when there was no response body', async ({page, server, browserName, platform}) => {
- server.setRoute('/get', (req, res) => {
- // In Firefox, |fetch| will be hanging until it receives |Content-Type| header
- // from server.
- res.setHeader('Content-Type', 'text/plain; charset=utf-8');
- res.end('');
- });
- await page.goto(server.EMPTY_PAGE);
- const [response] = await Promise.all([
- page.waitForEvent('response'),
- page.evaluate(async () => fetch('./get').then(r => r.text())),
- server.waitForRequest('/get'),
- ]);
+ const response = await page.goto(server.EMPTY_PAGE);
await response.finished();
expect(response.request().sizes().responseBodySize).toBe(0);
expect(response.request().sizes().responseHeadersSize).toBeGreaterThanOrEqual(150);