You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// Waits for the next response with the specified url
Response response = page.waitForResponse("https://example.com/resource", () -> {
// Triggers the response
page.getByText("trigger response").click();
});
But what should i do when i need to wait for several responses, triggered by one action?
if (response.request().url().contains("link1")){
assertThat(response.status()).isEqualTo(200);
}
if (response.request().url().contains("link2")){
assertThat(response.status()).isEqualTo(201);
}
if (response.request().url().contains("link3")){
assertThat(response.request().method()).isEqualTo("POST");
assertThat(response.status()).isEqualTo(204);
}
I agree, it's not very pretty, but the point is that I can check individually each request for compliance with the parameters.
Motivation
I have many cases when the frontend does not send requests immediately, but after some time. And it seems that the page is already loaded, although any interaction with it provokes an error. Yes, this is rather a question of page loading optimization, the correct order of requests execution, but even such not very well optimized frontend should be tested. Especially when sending requests in several stages (either according to requirements or because it is poorly done - it doesn't matter).
In any case, I need to be able to do the following somehow:
Make an action to trigger multiple requests
Wait for ALL requests to return with certain parameters.
I have written an example of how I see it, but maybe you can suggest a more convenient way to do it.
The text was updated successfully, but these errors were encountered:
You can pass a predicate that would match any of the 3 responses. And if you want to stick with waitForResponse API, you can nest 3 of them with the same predicate. Albeit ugly, it should work:
The problem with such API is it's not quite clear when such method should finish waiting, e.g. some urls may match multiple responses. In such case, you can just use waitForCondition:
🚀 Feature Request
There is one case documentated (i use Java):
But what should i do when i need to wait for several responses, triggered by one action?
Example
I need something like this
And using a loop I can check that for example (
I agree, it's not very pretty, but the point is that I can check individually each request for compliance with the parameters.
Motivation
I have many cases when the frontend does not send requests immediately, but after some time. And it seems that the page is already loaded, although any interaction with it provokes an error. Yes, this is rather a question of page loading optimization, the correct order of requests execution, but even such not very well optimized frontend should be tested. Especially when sending requests in several stages (either according to requirements or because it is poorly done - it doesn't matter).
In any case, I need to be able to do the following somehow:
I have written an example of how I see it, but maybe you can suggest a more convenient way to do it.
The text was updated successfully, but these errors were encountered: