Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
TypeScript automationchromechromiume2e-testingelectronend-to-end-testingfirefoxjavascriptplaywrighttesttest-automationtestingtesting-toolswebwebkit
feat(trace): include url into route.fulfill call params (#16934)
Yury Semikhatskyaaa28394cdf7
diff --git a/packages/playwright-core/src/server/dispatchers/networkDispatchers.ts b/packages/playwright-core/src/server/dispatchers/networkDispatchers.tsindex 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<Route, channels.RouteChannel, Re}async continue(params: channels.RouteContinueParams, metadata: CallMetadata): Promise<channels.RouteContinueResult> {+ // 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<Route, channels.RouteChannel, Re});}- async fulfill(params: channels.RouteFulfillParams): Promise<void> {+ async fulfill(params: channels.RouteFulfillParams, metadata: CallMetadata): Promise<void> {+ // 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<void> {+ async abort(params: channels.RouteAbortParams, metadata: CallMetadata): Promise<void> {+ // 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.tsindex 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, shoawait 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');+});+