javascripttestinge2e-testingcasperjsplaywright

Is there any Playwright equivalent for waitForResource in CasperJS?


Is there any Playwright equivalent for waitForResource in CasperJS? How can I write the below code using Playwright?

casper.waitForResource(function test(resource) {
    return resource.url.indexOf("submit") > -1;
}

Solution

  • You can use page.waitForRequest():

    await page.waitForRequest(request => request.url().indexOf('submit') > -1);
    

    This will pause the execution until a request is made that contains the string "submit" in its URL.