-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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] Setup default timeout to expect.toPass assertion #23937
Comments
This was intentionally made, we can add a new parameter to |
looks great, thx @mxschmitt |
It's super confusing right now to me... It's natural to think that the default expect timeout should be applied to all its features until the specific timeout is passed directly to the assertion. |
@mxschmitt I also got confused when I first found out that expect.toPass does not respect default expect timeout set in config - there are many expect.toPass assertions in our project and it would be good to be able to set the default timeout once |
Hi @mxschmitt! as you can check on above comment by @AdamOakman , I also need some way to set timeout on overall @dev-jonghoonpark made awesome PR #28231 to solve this problem. can you review this PR? thanks! 🙇 |
Is there at least a way how to access the default expect timeout from config? I am using |
For @gskierk, @AdamOakman, @uiii and who that confusing about
As you can see on above So If
So as you can check on above code, And by PR #28231, you can manually set some default timeout on toPass by config file~! After checking this, I think maybe it's better to add this description on doc#toPass#timeout 🤔 |
Hi @injae-kim
This is not fully true, it depends on what type of As you wrote that So if you use auto-retrying assertions in The reason why I use export async function toHaveTableData(locator: Locator, expected: string[][], options?: { timeout?: number }) {
try {
await expect(async () => {
const rows = locator.locator("> tbody > tr");
const rowCount = await rows.count();
expect(rowCount, "Table has unexpected number of rows").toBe(expected.length);
for (let i = 0; i < rowCount; ++i) {
const rowData = await rows.nth(i).locator("> td").allInnerTexts();
expect(rowData, `Row number ${i + 1} has unexpected data`).toEqual(expected[i]);
}
}).toPass(options);
return {
message: () => "Tables data are equal",
pass: true
};
} catch (e) {
return {
...e.matcherResult,
message: () => e.matcherResult.message,
};
}
} So if someone use it is really confusing as it uses different timeout: const table = page.getByTestId("table");
await expect(table).toBeVisible(); // <--- this uses default expect timeout (5s)
await expect(table).toHaveTableData(tableData /* string[][] */); // <---- this uses test timeout by default (60s) So I'd like to configure the Or, is there another way how to combine multiple expects in a custom matcher? Using auto-retrying assertions there, is even more problematic as they should share one timeout (passed to custom matcher), but there is no obvious way how to split it among multiple assertions. |
@uiii, oh~ thanks for your comment! I didn't know that playwright/packages/playwright/src/common/globals.ts Lines 43 to 51 in 5ef5e77
On your case (intentionally want to set expect.toPass's timeout same with expect's timeout), I think you can pass expect's timeout like above code using is this what you want? |
@injae-kim Unfortunately |
@uiii aha 😢 then I think we should use expect timeout directly on Hmm.. is it worth to make some way to access expect's timeout for user who wants to set |
Yeah, I did this as a workaround. |
Hey, is it possible to setup default timeout for expect.toPass assertions?
In case of usage
expect.toPass
without defining timeout in assertion the step will wait till the test timeout is exceed.Can we use here default expect config value?
config = { expect: { timeout: 10000 } }
Or add the new parameter into PlaywrightTestConfig
The text was updated successfully, but these errors were encountered: