Skip to content

sleep vs page.waitForTimeout #2084

@ankur22

Description

@ankur22

What

Users often use sleep when they should use page.waitForTimeout.

Solution

Use page.waitForTimeout instead of sleep. page.waitForTimeout is asynchronous and doesn't block the thread, allowing other background events to continue which is important for browser tests since there's usually a lot going on in the background. sleep is synchronous and blocks the thread, preventing other background tasks from completing. working with sleep will affect the measurements.

Create dedicated documentation for this. Currently this is detailed in: https://grafana.com/docs/k6/latest/using-k6-browser/recommended-practices/simulate-user-input-delay/ but i think it would be better in its own page.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions