- Navigating to some web page
- Waiting for something
- Possibly getting a timeout 😐
Navigating
Initial navigation to any page can happen in multiple ways.- Whenever your code does a
page.goto(), or apage.click()on a link, you explicitly trigger a navigation. - The webpage you are on can also trigger a navigation by executing
location.href= 'https://example.com'or using thehistory.pushState()API.
- The initial load of the page.
- A navigation to the shopping cart by clicking a link
basic-browser-navigation.spec.ts
Waiting
Waiting for something to happen is a crucial part of any automation script. In most cases, this is handled automatically by Playwright. For example, when you click a button, Playwright will wait for that button to be clickable before it actually clicks it. In the example below, we type an email address into an input field on a login modal. Playwright’sfill method comes with
built-in waiting functionality.
basic-browser-waiting.spec.ts
click() on a locator, Playwright will ensure that:
- your locator resolves to exactly one element.
- the matching element is visible.
- the matching element is stable.
- the matching element can receive events and is not covered or obscured by other elements.
- the matching element is enabled.
Timeouts
Thepage.waitForNavigation() method — but also similar methods like page.reload() and page.goBack() — all take some
options that determine “how” it should wait and what the timeout limits are.
These options come in two flavors:
1. Hard timeout
The time in milliseconds passed as the timeout property e.g.
page.waitForNavigation({ timeout: 2000 }). We do not recommend
using this if you do not explicitly need to.
2a. DOM event based
These two options are directly related to the events your browser emits when it has reached a certain loading stage.
load: This is thepage.goto()default and very strict: your whole page including all dependent resources, i.e. images, scripts, css etc.domcontentloaded: less strict: when your HTML has loaded.
networkidle: consider navigation to be finished when there are no more than 0 network connections for at least 500 ms.
Bugs don’t stop at CI/CD. Why would Playwright? 
Sign up and start using Playwright for end-to-end monitoring with Checkly.