Skip to content

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

test: add a test for disabled cache with context-wide request interception (#30072)

Andrey Lushnikov397244c0268a
diff --git a/tests/page/page-network-response.spec.ts b/tests/page/page-network-response.spec.ts
index b856362fa6..a4754f5f6e 100644
--- a/tests/page/page-network-response.spec.ts
+++ b/tests/page/page-network-response.spec.ts
@@ -348,7 +348,7 @@ it('should return body for prefetch script', async ({ page, server, browserName
expect(body.toString()).toBe('// Scripts will be pre-fetched');
});
-it('should bypass disk cache when interception is enabled', async ({ page, server, browserName }) => {
+it('should bypass disk cache when page interception is enabled', async ({ page, server, browserName }) => {
it.info().annotations.push({ type: 'issue', description: 'https://github.com/microsoft/playwright/issues/30000' });
it.fixme(browserName === 'firefox', 'Returns cached response.');
await page.goto(server.PREFIX + '/frames/one-frame.html');
@@ -399,3 +399,32 @@ it('should bypass disk cache when interception is enabled', async ({ page, serve
}
}
});
+
+it('should bypass disk cache when context interception is enabled', async ({ page, server, browserName }) => {
+ it.info().annotations.push({ type: 'issue', description: 'https://github.com/microsoft/playwright/issues/30000' });
+ it.fixme(browserName === 'firefox', 'Returns cached response.');
+ await page.context().route('**/api*', route => route.continue());
+ await page.goto(server.PREFIX + '/frames/one-frame.html');
+ {
+ const requests = [];
+ server.setRoute('/api', (req, res) => {
+ requests.push(req);
+ res.statusCode = 200;
+ res.setHeader('content-type', 'text/plain');
+ res.setHeader('cache-control', 'public, max-age=31536000');
+ res.end('Hello');
+ });
+ for (let i = 0; i < 3; i++) {
+ await it.step(`main frame iteration ${i}`, async () => {
+ const respPromise = page.waitForResponse('**/api');
+ await page.evaluate(async () => {
+ const response = await fetch('/api');
+ return response.status;
+ });
+ const response = await respPromise;
+ expect(response.status()).toBe(200);
+ expect(requests.length).toBe(i + 1);
+ });
+ }
+ }
+});