mirror of
https://github.com/microsoft/playwright.git
synced 2024-12-12 11:50:22 +03:00
test: add a test for request interception with redirects (#3994)
This commit is contained in:
parent
81c1daed73
commit
c2171218fa
@ -1654,6 +1654,8 @@ Routing provides the capability to modify network requests that are made by a pa
|
||||
|
||||
Once routing is enabled, every request matching the url pattern will stall unless it's continued, fulfilled or aborted.
|
||||
|
||||
> **NOTE** The handler will only be called for the first url if the response is a redirect.
|
||||
|
||||
An example of a naïve handler that aborts all image requests:
|
||||
|
||||
```js
|
||||
|
@ -37,14 +37,40 @@ it('should work for subframe navigation request', async ({page, server}) => {
|
||||
|
||||
it('should work for fetch requests', async ({page, server}) => {
|
||||
await page.goto(server.EMPTY_PAGE);
|
||||
let requests = [];
|
||||
const requests = [];
|
||||
page.on('request', request => requests.push(request));
|
||||
await page.evaluate(() => fetch('/digits/1.png'));
|
||||
requests = requests.filter(request => !request.url().includes('favicon'));
|
||||
expect(requests.length).toBe(1);
|
||||
expect(requests[0].frame()).toBe(page.mainFrame());
|
||||
});
|
||||
|
||||
it('should work for a redirect', async ({page, server}) => {
|
||||
server.setRedirect('/foo.html', '/empty.html');
|
||||
const requests = [];
|
||||
page.on('request', request => requests.push(request));
|
||||
await page.goto(server.PREFIX + '/foo.html');
|
||||
|
||||
expect(requests.length).toBe(2);
|
||||
expect(requests[0].url()).toBe(server.PREFIX + '/foo.html');
|
||||
expect(requests[1].url()).toBe(server.PREFIX + '/empty.html');
|
||||
});
|
||||
|
||||
// https://github.com/microsoft/playwright/issues/3993
|
||||
it('should not work for a redirect and interception', async ({page, server}) => {
|
||||
server.setRedirect('/foo.html', '/empty.html');
|
||||
const requests = [];
|
||||
await page.route('**', route => {
|
||||
requests.push(route.request());
|
||||
route.continue();
|
||||
});
|
||||
await page.goto(server.PREFIX + '/foo.html');
|
||||
|
||||
expect(page.url()).toBe(server.PREFIX + '/empty.html');
|
||||
|
||||
expect(requests.length).toBe(1);
|
||||
expect(requests[0].url()).toBe(server.PREFIX + '/foo.html');
|
||||
});
|
||||
|
||||
it('should return headers', async ({page, server, isChromium, isFirefox, isWebKit}) => {
|
||||
const response = await page.goto(server.EMPTY_PAGE);
|
||||
if (isChromium)
|
||||
|
Loading…
Reference in New Issue
Block a user