diff --git a/test/src/network.spec.ts b/test/src/network.spec.ts index 074f9efba4e..fb9eedce612 100644 --- a/test/src/network.spec.ts +++ b/test/src/network.spec.ts @@ -911,13 +911,8 @@ describe('network', function () { it('should work for document type', async () => { const {page, server} = await getTestState(); - const requests: HTTPRequest[] = []; - page.on('request', request => { - return requests.push(request); - }); - await page.goto(server.EMPTY_PAGE); - expect(requests).toHaveLength(1); - const request = requests[0]!; + const response = await page.goto(server.EMPTY_PAGE); + const request = response!.request(); expect(request.resourceType()).toBe('document'); }); @@ -942,13 +937,7 @@ describe('network', function () { it('should work', async () => { const {page, server} = await getTestState(); - const responses: HTTPResponse[] = []; - page.on('response', response => { - return responses.push(response); - }); - await page.goto(server.EMPTY_PAGE); - expect(responses).toHaveLength(1); - const response = responses[0]!; + const response = (await page.goto(server.EMPTY_PAGE))!; const remoteAddress = response.remoteAddress(); // Either IPv6 or IPv4, depending on environment. expect( diff --git a/test/src/requestinterception-experimental.spec.ts b/test/src/requestinterception-experimental.spec.ts index c64c9ffc254..f8437b36d2f 100644 --- a/test/src/requestinterception-experimental.spec.ts +++ b/test/src/requestinterception-experimental.spec.ts @@ -1008,14 +1008,11 @@ describe('cooperative request interception', function () { const {page, server} = await getTestState(); await page.setRequestInterception(true); - const requests: HTTPRequest[] = []; page.on('request', request => { - requests.push(request); void request.continue({}, 0); }); - await page.goto(server.EMPTY_PAGE); - expect(requests).toHaveLength(1); - const request = requests[0]!; + const response = await page.goto(server.EMPTY_PAGE); + const request = response!.request(); expect(request.resourceType()).toBe('document'); }); diff --git a/test/src/requestinterception.spec.ts b/test/src/requestinterception.spec.ts index c2fe0d0a3cb..1308294ed4d 100644 --- a/test/src/requestinterception.spec.ts +++ b/test/src/requestinterception.spec.ts @@ -937,14 +937,11 @@ describe('request interception', function () { const {page, server} = await getTestState(); await page.setRequestInterception(true); - const requests: HTTPRequest[] = []; page.on('request', request => { - requests.push(request); void request.continue(); }); - await page.goto(server.EMPTY_PAGE); - expect(requests).toHaveLength(1); - const request = requests[0]!; + const response = await page.goto(server.EMPTY_PAGE); + const request = response!.request(); expect(request.resourceType()).toBe('document'); });