Closed eveltman-twinfield closed 2 weeks ago
You can use context.waitForEvent('response')
for that:
import { test, expect } from '@playwright/test';
test("context wait for response", async ({ page, context }) => {
const responsePromise = context.waitForEvent('response', (response) => response.url().includes('playwright-logo.svg'));
await page.goto("https://playwright.dev");
const response = await responsePromise;
expect(response.status()).toBe(200);
});
🚀 Feature Request
Hi, I'd like waitForResponse to be available on BrowserContext. Right now we can only use it on Page level.
Example
Since it wasn't available, this our own implementation. (Note: I omitted the actual usage in the test, but triggerAction is a function which clicks somewhere in the application to open a popup)
Motivation
Today I was assisting a QA with verifying that a popup page was making a successful API request (to load a PDF in an iframe). We were checking not only that the URL (requested by the application) contained the expected invoice id but also that the request would return a success response. Since the API request is done in a popup, we could not use page.waitForResponse. By the time the popup event occurs and by the time we handled that event and attached a response handler to it, the API response may already have been received.
I initially was convinced we could just do context.waitForResponse but it didn't exist.