-
Notifications
You must be signed in to change notification settings - Fork 229
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Feature] Add Expect.Poll #2314
Comments
Would the suggestion below be a good starting point? FYI my current solution is further below. If a similar thing is good enough (but including backoff intervals and a
My current solution:
|
I would recommend Task.Delay instead, otherwise it looks reasonable! |
implements microsoft#2314
@mxschmitt could you have a look at the linked commit please? Is this usable? |
Looks great! But more like Expect.ToPass rather than Poll. I think we could reshape it a bit, so it matches with the JavaScript API for ToPass and then close the Expect.Poll feature request: await Expect(async () =>
{
var foo = await Page.EvaluateAsync<string>("() => document.title");
Assert.AreEqual("Hello world", foo);
}).ToPassAsync(new () {
Intervals = new[] { 1_000, 2_000, 10_000 },
Timeout = 60_000,
}); Something like this I was envisioning. If we want to implement expect.Poll, it should look like this: await Expect.Poll(async () => {
var response = await Page.APIRequest.GetAsync("https://api.example.com");
return response.Status;
}, new() {
// Custom error message, optional.
message = "make sure API eventually succeeds", // custom error message
// Poll for 10 seconds; defaults to 5 seconds. Pass 0 to disable timeout.
timeout: 10000,
}).toBeAsync(200); Which is much more effort to implement, since we don't have the "default expect matchers like toBe" in .NET compared to Node.js where we get them from the expect Library. In .NET we have Assert for that. So this seems out of scope and ToPass like you did seems like a great feature! |
@mxschmitt Okay, I understand and will adapt. I'll also update the logic so it ignores any exceptions until success or timeout. |
See here: https://playwright.dev/docs/test-assertions#polling
The text was updated successfully, but these errors were encountered: