mirror of
https://github.com/microsoft/playwright.git
synced 2025-01-05 19:04:43 +03:00
test: intercepted response status line (#8189)
This commit is contained in:
parent
8231aa3919
commit
39f663834f
@ -487,7 +487,8 @@ class RouteImpl implements network.RouteDelegate {
|
||||
return null;
|
||||
const event = await this._responseInterceptedPromise;
|
||||
this._interceptionId = event.requestId;
|
||||
return new network.InterceptedResponse(request, event.responseStatusCode!, event.responseErrorReason!, event.responseHeaders!);
|
||||
// FIXME: plumb status text from browser
|
||||
return new network.InterceptedResponse(request, event.responseStatusCode!, '', event.responseHeaders!);
|
||||
}
|
||||
|
||||
async fulfill(response: types.NormalizedFulfillResponse) {
|
||||
|
@ -113,7 +113,7 @@ it('should give access to the intercepted response', async ({page, server}) => {
|
||||
const routePromise = new Promise<Route>(f => routeCallback = f);
|
||||
await page.route('**/title.html', routeCallback);
|
||||
|
||||
const evalPromise = page.evaluate(url => fetch(url), server.PREFIX + '/title.html').catch(console.log);
|
||||
const evalPromise = page.evaluate(url => fetch(url), server.PREFIX + '/title.html');
|
||||
|
||||
const route = await routePromise;
|
||||
// @ts-expect-error
|
||||
@ -127,6 +127,29 @@ it('should give access to the intercepted response', async ({page, server}) => {
|
||||
await Promise.all([route.fulfill(), evalPromise]);
|
||||
});
|
||||
|
||||
it('should give access to the intercepted response status text', async ({page, server, browserName}) => {
|
||||
it.fail(browserName === 'chromium', 'Status line is not reported for intercepted responses');
|
||||
await page.goto(server.EMPTY_PAGE);
|
||||
server.setRoute('/title.html', (req, res) => {
|
||||
res.statusCode = 200;
|
||||
res.statusMessage = 'You are awesome';
|
||||
res.setHeader('Content-Type', 'text/plain');
|
||||
res.end();
|
||||
});
|
||||
let routeCallback;
|
||||
const routePromise = new Promise<Route>(f => routeCallback = f);
|
||||
await page.route('**/title.html', routeCallback);
|
||||
const evalPromise = page.evaluate(url => fetch(url), server.PREFIX + '/title.html');
|
||||
const route = await routePromise;
|
||||
// @ts-expect-error
|
||||
const response = await route._intercept();
|
||||
|
||||
expect(response.statusText()).toBe('You are awesome');
|
||||
expect(response.url()).toBe(server.PREFIX + '/title.html');
|
||||
|
||||
await Promise.all([route.fulfill(), evalPromise]);
|
||||
});
|
||||
|
||||
it('should give access to the intercepted response body', async ({page, server}) => {
|
||||
await page.goto(server.EMPTY_PAGE);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user