Search code examples
network-programmingplaywright

Playwright how to wait for couple of requests?


I have a very slow web site which loads couple of requests I'd like to wait for. Here is an example of my code:

 await page.waitForRequest("/api/data/pagesTree1");
 await page.waitForRequest("/api/data/pagesTree2");
 await page.waitForRequest("/api/data/pagesTree3");

But happens next: for example pagesTree1 is going, test waits for it, but pagesTree2 and 3 are already here, when second waitForRequest starts, it fails, because the request has arrived already, how can I handle this situation ?

Can I do something like:

await page.waitForRequest(["request1", "request2", ...]);

I mean waiting all of them at the same time. Or there are other better approaches ?


Solution

  • okay, I can do next:

    await Promise.all([
                page.waitForResponse(resp => resp.url().includes('/api/data/pagesTree1') && resp.status() === 200),
                page.waitForResponse(resp => resp.url().includes('/api/pagesTree2') && resp.status() === 200),
                page.waitForResponse(resp => resp.url().includes('/api/pagesTree3') && resp.status() === 200),
            ]);