feat(navigation): waitForNavigation/goto should not wait until response finished (#1225)
This commit is contained in:
parent
31278408db
commit
5ff660de15
|
|
@ -3185,6 +3185,7 @@ ResourceType will be one of the following: `document`, `stylesheet`, `image`, `m
|
||||||
|
|
||||||
<!-- GEN:toc -->
|
<!-- GEN:toc -->
|
||||||
- [response.buffer()](#responsebuffer)
|
- [response.buffer()](#responsebuffer)
|
||||||
|
- [response.finished()](#responsefinished)
|
||||||
- [response.frame()](#responseframe)
|
- [response.frame()](#responseframe)
|
||||||
- [response.headers()](#responseheaders)
|
- [response.headers()](#responseheaders)
|
||||||
- [response.json()](#responsejson)
|
- [response.json()](#responsejson)
|
||||||
|
|
@ -3199,6 +3200,9 @@ ResourceType will be one of the following: `document`, `stylesheet`, `image`, `m
|
||||||
#### response.buffer()
|
#### response.buffer()
|
||||||
- returns: <Promise<[Buffer]>> Promise which resolves to a buffer with response body.
|
- returns: <Promise<[Buffer]>> Promise which resolves to a buffer with response body.
|
||||||
|
|
||||||
|
#### response.finished()
|
||||||
|
- returns: <Promise[?string]> Waits for this response to finish, throws when corresponding request failed.
|
||||||
|
|
||||||
#### response.frame()
|
#### response.frame()
|
||||||
- returns: <?[Frame]> A [Frame] that initiated this response, or `null` if navigating to error pages.
|
- returns: <?[Frame]> A [Frame] that initiated this response, or `null` if navigating to error pages.
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -165,9 +165,7 @@ export class Request {
|
||||||
}
|
}
|
||||||
|
|
||||||
async _waitForResponse(): Promise<Response> {
|
async _waitForResponse(): Promise<Response> {
|
||||||
const response = await this._waitForResponsePromise;
|
return await this._waitForResponsePromise;
|
||||||
await response._finishedPromise;
|
|
||||||
return response;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_setResponse(response: Response) {
|
_setResponse(response: Response) {
|
||||||
|
|
@ -271,6 +269,10 @@ export class Response {
|
||||||
return this._headers;
|
return this._headers;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
finished(): Promise<Error | null> {
|
||||||
|
return this._finishedPromise;
|
||||||
|
}
|
||||||
|
|
||||||
buffer(): Promise<platform.BufferType> {
|
buffer(): Promise<platform.BufferType> {
|
||||||
if (!this._contentPromise) {
|
if (!this._contentPromise) {
|
||||||
this._contentPromise = this._finishedPromise.then(async error => {
|
this._contentPromise = this._finishedPromise.then(async error => {
|
||||||
|
|
|
||||||
|
|
@ -258,21 +258,23 @@ module.exports.describe = function({testRunner, expect, MAC, WIN, FFOX, CHROMIUM
|
||||||
expect(failedRequests[0].frame()).toBeTruthy();
|
expect(failedRequests[0].frame()).toBeTruthy();
|
||||||
});
|
});
|
||||||
it('Page.Events.RequestFinished', async({page, server}) => {
|
it('Page.Events.RequestFinished', async({page, server}) => {
|
||||||
const requests = [];
|
const [response] = await Promise.all([
|
||||||
page.on('requestfinished', request => requests.push(request));
|
page.goto(server.EMPTY_PAGE),
|
||||||
await page.goto(server.EMPTY_PAGE);
|
page.waitForEvent('requestfinished')
|
||||||
expect(requests.length).toBe(1);
|
]);
|
||||||
expect(requests[0].url()).toBe(server.EMPTY_PAGE);
|
const request = response.request();
|
||||||
expect(requests[0].response()).toBeTruthy();
|
expect(request.url()).toBe(server.EMPTY_PAGE);
|
||||||
expect(requests[0].frame() === page.mainFrame()).toBe(true);
|
expect(request.response()).toBeTruthy();
|
||||||
expect(requests[0].frame().url()).toBe(server.EMPTY_PAGE);
|
expect(request.frame() === page.mainFrame()).toBe(true);
|
||||||
|
expect(request.frame().url()).toBe(server.EMPTY_PAGE);
|
||||||
});
|
});
|
||||||
it('should fire events in proper order', async({page, server}) => {
|
it('should fire events in proper order', async({page, server}) => {
|
||||||
const events = [];
|
const events = [];
|
||||||
page.on('request', request => events.push('request'));
|
page.on('request', request => events.push('request'));
|
||||||
page.on('response', response => events.push('response'));
|
page.on('response', response => events.push('response'));
|
||||||
page.on('requestfinished', request => events.push('requestfinished'));
|
const response = await page.goto(server.EMPTY_PAGE);
|
||||||
await page.goto(server.EMPTY_PAGE);
|
await response.finished();
|
||||||
|
events.push('requestfinished')
|
||||||
expect(events).toEqual(['request', 'response', 'requestfinished']);
|
expect(events).toEqual(['request', 'response', 'requestfinished']);
|
||||||
});
|
});
|
||||||
it('should support redirects', async({page, server}) => {
|
it('should support redirects', async({page, server}) => {
|
||||||
|
|
@ -284,6 +286,7 @@ module.exports.describe = function({testRunner, expect, MAC, WIN, FFOX, CHROMIUM
|
||||||
server.setRedirect('/foo.html', '/empty.html');
|
server.setRedirect('/foo.html', '/empty.html');
|
||||||
const FOO_URL = server.PREFIX + '/foo.html';
|
const FOO_URL = server.PREFIX + '/foo.html';
|
||||||
const response = await page.goto(FOO_URL);
|
const response = await page.goto(FOO_URL);
|
||||||
|
await response.finished();
|
||||||
expect(events).toEqual([
|
expect(events).toEqual([
|
||||||
`GET ${FOO_URL}`,
|
`GET ${FOO_URL}`,
|
||||||
`302 ${FOO_URL}`,
|
`302 ${FOO_URL}`,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue