Can anyone tell me if there is any way to validate routes regardless of whether they have already been completed or not?
My tests are becoming unstable when using route validation. From what I analyzed and it is very clear, if a route has already been completed, playwright can no longer validate it.
In other words, the route will only be validated if it is being processed or has not yet been started.
Does anyone know if there is a way to validate the route even if it is already finished?
This thread is trying to answer question "Is there a way to validate a route in Playwright even if it has already been completed?"
Sorry for that @viraxslot .
This is my code:
async awaitSuccessfulApiCallClaimID(claimID, method, status = 204) { await this.page.waitForResponse((resp) => resp.url().includes(claimID) && resp.status() == status && resp.request().method() === method); }
And when i run in the pipeline (sometimes locally too) i get this error:
Got it. Possible ways of analyzing this.
Promise.all
and include both "action that triggers request" and your "function that waits for the response".Hope it'll help
Thank you for the awsnser @viraxslot !
About the points:
I really don't know what happens.
With promise.all:
await Promise.all([ list.searchByClaimName(newClaimName), helper.awaitSuccessfulApiCallClaimID(newClaimName, 'GET') ]);
Yeah, it's hard to say without seeing the code. But I got similar problems on my project too and it's 99.99% not playwright problem ๐
Is claimID
just a string?
It's not related to the problem, but I'd not include "await" into your function name. If you're worried to miss await
keyword then configure eslint to check this.
As for me await awaitSuccessfulApiCallClaimID()
looks really strange.
Have you made sure that the waitForResponse
promise is done before your navigation, and then the await of the promise is after? EG:
// initialize the promise before the action that triggers the request
const responsePromise = page.waitForResponse(
(response) =>
response.url() === "https://example.com" && response.status() === 200
);
const [response] = await Promise.all([
responsePromise,
someButton.click(), //make sure the action is the last promise in the list
]);
I'm not sure if just putting your wrapper function before your action in the promise.All
will do it. You could try making a const just before your action and then passing the promise with your action in the promise.All, like this:
const deletePromise = helper.awaitSuccessfulApiCallClaimID(claimID, 'DELETE')
await Promise.all([
deletePromise,
list.delete()
]);
Hey @.graff
sorry for being late.
I changed my code considering your suggestion, but I still have the same problem ๐ฆ I ran it locally for a long time and the test passed, but when I ran it in the pipeline, it became unstable.
const awaitRouteDownloadClaimPromise = helper.awaitSuccessfulApiCallClaimID(claimID, 'PATCH');
await Promise.all([
awaitRouteDownloadClaimPromise,
demurrageClaimManager.fillClaimName(downloadClaimName),
]);
I doubt if this is related to missing await
. Page closed error usually occurs when you forgot to await somewhere in your code. Just to be safe, try using @typescript-eslint/no-floating-promises
ESLint rule to make sure there are no missing awaits before the asynchronous calls to the Playwright API.
Reference: https://playwright.dev/docs/best-practices#lint-your-tests
Rayrun is a community for QA engineers. I am constantly looking for new ways to add value to people learning Playwright and other browser automation frameworks. If you have feedback, email [email protected].