playwright icon indicating copy to clipboard operation
playwright copied to clipboard

[Feature] Enable toBeOK matcher also for Response interface

Open sunker opened this issue 2 years ago • 2 comments

I would like the toBeOK matcher to apply also to the Response interface.

// the following is simply more expressive 
const response = await page.waitForResponse('https://example.com/resource');
await expect(response).toBeOK();

// ..than doing this
const response = await page.waitForResponse('https://example.com/resource');
await expect(response.ok()).toBeTruthy();

It makes no sense that this matcher applies to APIResponse interface but not Response interface.

This feature request has been raised before: https://github.com/microsoft/playwright/issues/12171

sunker avatar Jan 30 '24 09:01 sunker

Hi, is this what you are looking for?

https://playwright.dev/docs/api/class-apiresponseassertions#api-response-assertions-to-be-ok

ltsuda avatar Jan 30 '24 11:01 ltsuda

The receiving type of the toBeOK matcher is currently APIResponse. I would like the toBeOK matcher to also accept Response as receiving type.

sunker avatar Jan 30 '24 12:01 sunker

I would like this as well. The use case I just came across was a "document viewer" side panel being used on a page. The document viewer was loading a PDF document in an iframe. We cannot interact with the PDF viewer but we wanted to at least verify that the URL passed to the document viewer was correct and returning a successful response.

eveltman-twinfield avatar May 16 '24 15:05 eveltman-twinfield