Skip to content

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

test: responseSize incorrect for 404 with content (#9328)

Ross Wollmandbc3c11b8e34
diff --git a/tests/page/page-network-sizes.spec.ts b/tests/page/page-network-sizes.spec.ts
index 384ec66c18..f9485eddff 100644
--- a/tests/page/page-network-sizes.spec.ts
+++ b/tests/page/page-network-sizes.spec.ts
@@ -167,3 +167,31 @@ for (const statusCode of [200, 401, 404, 500]) {
expect(sizes.responseBodySize).toBe(3);
});
}
+
+it('should have correct responseBodySize for 404 with content', async ({ page, server, browserName }) => {
+ it.fail(browserName === 'chromium');
+
+ server.setRoute('/broken-image.png', (req, resp) => {
+ resp.writeHead(404);
+ resp.end(`<p>this should have a non-negative size</p>`);
+ });
+ server.setRoute('/page-with-404-image.html', (req, resp) => {
+ resp.end(`
+ <!DOCTYPE html>
+ <html>
+ <head><title>Page with Broken Image</title></head>
+ <body>
+ <img src="/broken-image.png" />
+ </body>
+ </html>
+ `);
+ });
+
+ const [req] = await Promise.all([
+ page.waitForRequest(/broken-image\.png$/),
+ page.goto(server.PREFIX + '/page-with-404-image.html'),
+ ]);
+
+ const { responseBodySize } = await req.sizes();
+ expect(responseBodySize).toBeGreaterThanOrEqual(0);
+});