Skip to content
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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

ankur22
Copy link
Contributor

@ankur22 ankur22 commented Sep 19, 2024

What?

This new page details recommendation on sleep and the various wait* functions available to the browser module. The main reason for doing this is to guide users away from working with sleep and instead work with the various wait* APIs, specifically replacing sleep with page.waitForTimeout.

Checklist

  • I have used a meaningful title for the PR.
  • I have described the changes I've made in the "What?" section above.
  • I have performed a self-review of my changes.
  • I have run the npm start command locally and verified that the changes look good.
  • I have made my changes in the docs/sources/next folder of the documentation.

Related PR(s)/Issue(s)

Updates: #1719

@ankur22 ankur22 marked this pull request as draft September 19, 2024 14:32
@ankur22 ankur22 force-pushed the add/sleep-wait-browser branch 4 times, most recently from b6e2060 to 6139ac2 Compare September 23, 2024 15:29
@ankur22 ankur22 marked this pull request as ready for review September 23, 2024 15:31
Copy link
Member

@inancgumus inancgumus left a 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)
Copy link
Member

@inancgumus inancgumus Sep 23, 2024

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.

Suggested change
- [`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.
Copy link
Member

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 use wait* prepended methods for reliable tests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants