Implement fix without retries when working with `locator.waitFor` which can error during a page navigation
Opened this issue · 0 comments
What
When working with locator.waitFor
, it will error causing the iteration to end early if a navigation occurs while the waitFor
is waiting. This happens when we perform something like:
await page.goto('some-url') // Pointing to a URL which perform multiple redirects such as login via SSO
await page.locator('some-selector').waitFor() // This can fail if the navigation is still redirecting/not completed
Multiple errors can occur:
- "Inspected target navigated or closed"
- "Cannot find context with specified id"
- "Execution context was destroyed"
We have implemented a workaround which can be found in #1469, which will detect the errors listed above and retry again, with the hopes that eventually the navigation will complete and the element is found that matches the selector.
Why
Although we have a workaround, it doesn't feel like the correct one and it is limited by a retry count of 20. We need to work out a longer term solution without relying on a retry. Looking at Playwright and Puppeteer might help work out how to best work with waitFor
when navigating.
related: #1472, https://github.com/grafana/xk6-browser/pull/1469/files