From aaa28394cdf715a41c1192af09cdd7d46a9fff69 Mon Sep 17 00:00:00 2001 From: Yury Semikhatsky Date: Wed, 31 Aug 2022 12:37:49 -0700 Subject: [PATCH] feat(trace): include url into route.fulfill call params (#16934) --- .../server/dispatchers/networkDispatchers.ts | 10 +++- tests/library/trace-viewer.spec.ts | 53 +++++++++++++++++++ 2 files changed, 61 insertions(+), 2 deletions(-) diff --git a/packages/playwright-core/src/server/dispatchers/networkDispatchers.ts b/packages/playwright-core/src/server/dispatchers/networkDispatchers.ts index b5e33ab4e9..83578ce291 100644 --- a/packages/playwright-core/src/server/dispatchers/networkDispatchers.ts +++ b/packages/playwright-core/src/server/dispatchers/networkDispatchers.ts @@ -128,6 +128,8 @@ export class RouteDispatcher extends Dispatcher { + // Used to discriminate between continue in tracing. + metadata.params.requestUrl = this._object.request().url(); await this._object.continue({ url: params.url, method: params.method, @@ -136,11 +138,15 @@ export class RouteDispatcher extends Dispatcher { + async fulfill(params: channels.RouteFulfillParams, metadata: CallMetadata): Promise { + // Used to discriminate between fulfills in tracing. + metadata.params.requestUrl = this._object.request().url(); await this._object.fulfill(params); } - async abort(params: channels.RouteAbortParams): Promise { + async abort(params: channels.RouteAbortParams, metadata: CallMetadata): Promise { + // Used to discriminate between abort in tracing. + metadata.params.requestUrl = this._object.request().url(); await this._object.abort(params.errorCode || 'failed'); } diff --git a/tests/library/trace-viewer.spec.ts b/tests/library/trace-viewer.spec.ts index 2e17aeea5b..5c148811bc 100644 --- a/tests/library/trace-viewer.spec.ts +++ b/tests/library/trace-viewer.spec.ts @@ -633,3 +633,56 @@ test('should open two trace files', async ({ context, page, request, server, sho await expect(callLine.locator('text=events')).toHaveText(/events: [\d]+/); }); +test('should include requestUrl in route.fulfill', async ({ page, runAndTrace, browserName }) => { + await page.route('**/*', route => { + route.fulfill({ + status: 200, + headers: { + 'content-type': 'text/html' + }, + body: 'Hello there!' + }); + }); + const traceViewer = await runAndTrace(async () => { + await page.goto('http://test.com'); + }); + + // Render snapshot, check expectations. + await traceViewer.selectAction('route.fulfill'); + await traceViewer.page.locator('.tab-label', { hasText: 'Call' }).click(); + const callLine = traceViewer.page.locator('.call-line'); + await expect(callLine.locator('text=status')).toContainText('200'); + await expect(callLine.locator('text=requestUrl')).toContainText('http://test.com'); +}); + +test('should include requestUrl in route.continue', async ({ page, runAndTrace, server }) => { + await page.route('**/*', route => { + route.continue({ url: server.EMPTY_PAGE }); + }); + const traceViewer = await runAndTrace(async () => { + await page.goto('http://test.com'); + }); + + // Render snapshot, check expectations. + await traceViewer.selectAction('route.continue'); + await traceViewer.page.locator('.tab-label', { hasText: 'Call' }).click(); + const callLine = traceViewer.page.locator('.call-line'); + await expect(callLine.locator('text=requestUrl')).toContainText('http://test.com'); + await expect(callLine.locator('text=/^url: .*/')).toContainText(server.EMPTY_PAGE); +}); + +test('should include requestUrl in route.abort', async ({ page, runAndTrace, server }) => { + await page.route('**/*', route => { + route.abort(); + }); + const traceViewer = await runAndTrace(async () => { + await page.goto('http://test.com').catch(() => {}); + }); + + // Render snapshot, check expectations. + await traceViewer.selectAction('route.abort'); + await traceViewer.page.locator('.tab-label', { hasText: 'Call' }).click(); + const callLine = traceViewer.page.locator('.call-line'); + await expect(callLine.locator('text=requestUrl')).toContainText('http://test.com'); +}); +