This thread is trying to answer question "Is there a way to refresh a page until an element is shown for testing purposes?"
expect.poll
is a possibility: https://playwright.dev/docs/test-assertions#expectpoll
expect.toPass() is also an option: https://playwright.dev/docs/test-assertions#expecttopass
Yep expect poll. What I did was
Set timeout in the test for limit of 70s
Perform the action and return certain responses
Validate the response to be an Object if this is the expected result.
Otherwise return String and retry at interval of 10s, 20s, 30s
await expect.poll(async () => { try { perform the action return resultOfTheAction } catch (error) { return 'NA' } }, { // Custom error message, optional. message: 'custom message', // Poll for 60 seconds; intervals: [10_000, 20_000, 30_000], timeout: 60_000, }).toBeInstanceOf(Object);
Applying it in various scenarios by changing the action and the return verification.
For example: if my expected final page contains 2 Elements. Then my Objects array containing all the elements needs to have the return length of 2 .toEqual(2). If it doesn't cause it takes extra time to load, return 0 and retry
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].