playwright icon indicating copy to clipboard operation
playwright copied to clipboard

[Feature] Better logs in trace viewer for waitForRequest/waitForResponse

Open A-ZC-Lau opened this issue 3 years ago • 4 comments

Is it possible to get the request and response from a waitForRequest and waitForResponse in the trace viewer? Because right now, it really lacks any information to help debug.

It doesn't even have information on what URL it fulfilled

Screenshot 2022-12-06 at 11 44 27 am

A-ZC-Lau avatar Dec 06 '22 00:12 A-ZC-Lau

@A-ZC-Lau what language are you using? Is it Java?

aslushnikov avatar Dec 06 '22 17:12 aslushnikov

@aslushnikov javascript

A-ZC-Lau avatar Dec 07 '22 00:12 A-ZC-Lau

@A-ZC-Lau

I tried the following simple test:

// a.spec.ts
import { test, expect } from '@playwright/test';

test('should work', async ({ page }) => {
  await Promise.all([
    page.goto('https://example.com'),
    page.waitForRequest('https://example.com'),
  ]);
});

And I ended up with the following trace that has a URL:

Screenshot 2022-12-06 at 3 01 48 PM

Could you please try this? Does it work for you?

aslushnikov avatar Dec 07 '22 01:12 aslushnikov

@aslushnikov I'm running my tests using the function way

import {test} from "@playwright/test";

const api = "https://www.airbnb.com.au/api/v2/user_markets";


test("waitForRequest", async function ({page}) {
	const r = new RegExp(api);
	await page.route(r, route => {
		route.fulfill({
			body : "",
			status : 200,
		});
	});

	const [req] = await Promise.all([
		page.waitForRequest(route => {
			const url = route.url().match(r);
			const method = route.method() === "GET";
			return !!url && method;
		}),
		page.goto("https://www.airbnb.com"),
	]);
});

But even with the string parameter, it doesn't show what the request/response (for waitForResponse) were.

Would it be possible to have these details added in future versions?

A-ZC-Lau avatar Dec 07 '22 03:12 A-ZC-Lau

I landed here from Google trying to find #15690

Commenting in case future travelers are in the same boat

aldenquimby avatar Mar 14 '23 20:03 aldenquimby