-
Notifications
You must be signed in to change notification settings - Fork 217
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
Add a page on sleep and wait for browser module #1730
base: main
Are you sure you want to change the base?
Conversation
b6e2060
to
6139ac2
Compare
6139ac2
to
6c5e6e1
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome 👍
@@ -11,3 +11,4 @@ This section presents some examples and recommended practices when working with | |||
- [Hybrid approach to performance](https://grafana.com/docs/k6/<K6_VERSION>/using-k6-browser/recommended-practices/hybrid-approach-to-performance) | |||
- [Page object model pattern](https://grafana.com/docs/k6/<K6_VERSION>/using-k6-browser/recommended-practices/page-object-model-pattern) | |||
- [Selecting elements](https://grafana.com/docs/k6/<K6_VERSION>/using-k6-browser/recommended-practices/selecting-elements) | |||
- [`sleep` and `wait*`](https://grafana.com/docs/k6/<K6_VERSION>/using-k6-browser/recommended-practices/sleep-and-wait) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd suggest using human-readable text, also to be consistent with the other links in this list.
- [`sleep` and `wait*`](https://grafana.com/docs/k6/<K6_VERSION>/using-k6-browser/recommended-practices/sleep-and-wait) | |
- [Simulating wait operations](https://grafana.com/docs/k6/<K6_VERSION>/using-k6-browser/recommended-practices/sleep-and-wait) |
|
||
To avoid flaky tests, avoid working with `sleep` or `page.waitForTimeout` to wait for state changes with an element (such as waiting for elements to appear/disappear or navigating to a different page). | ||
|
||
They are, however, useful for mimicking a real user by slowing the test down between API calls, or to debug your test. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd put this line in the first paragraph to avoid confusion. Otherwise, users might think they can still use those and unintentionally face unexpected behavior. Maybe:
While using the
sleep
function to wait for element state changes can be helpful, it's best to avoid it to prevent unreliable tests. Instead, it's better to usewait*
prepended methods for reliable tests.
What?
This new page details recommendation on
sleep
and the variouswait*
functions available to the browser module. The main reason for doing this is to guide users away from working withsleep
and instead work with the variouswait*
APIs, specifically replacingsleep
withpage.waitForTimeout
.Checklist
npm start
command locally and verified that the changes look good.docs/sources/next
folder of the documentation.Related PR(s)/Issue(s)
Updates: #1719