All challenges · Foundations

Challenge 1 of 29 · Beginner-friendly · Foundations

Navigate to a Page with Playwright

Your first Playwright action: open a website in a real browser. You learn what page and await mean, and a hidden check confirms you reached the right page.

Skills you will practise

  • page.goto
  • await
  • how a test starts

The concept

Every Playwright test starts somewhere, and usually that is page.goto(). The page object represents a single browser tab. Calling page.goto(url) tells that tab to load a URL and, by default, waits until the page fires its load event before your next line runs.

Nearly every Playwright method returns a Promise, which is why you see await in front of almost every line. await pauses your test until the action has finished. Without it, your script races ahead and the next step may run against a page that has not loaded yet.

Loading a page is not the same as checking you landed on the right one. Redirects, login walls and typos can all leave you somewhere else, so a good first test asserts on the URL or title.

The fragile version

Fragile
page.goto('https://example.com/dashboard'); // no await
await page.getByRole('heading', { name: 'Dashboard' }).click();

Why it breaks: The missing await means the navigation starts but the test does not wait for it. The next line may run before the page exists, and an unhandled rejected Promise can surface as a confusing error later in the run.

A robust Playwright version

Robust
await page.goto('https://example.com/dashboard');
await expect(page).toHaveURL(/\/dashboard/);
await expect(page.getByRole('heading', { name: 'Dashboard' })).toBeVisible();

Each step is awaited, and the web-first assertions retry until the URL and heading match, so the test confirms where it actually ended up.

This is a general example on a made-up page, not the challenge’s reference solution.

Common mistakes

  • Forgetting await on goto or on an assertion.
  • Assuming goto succeeded without checking the URL or a heading.
  • Adding waitForTimeout(3000) after navigation instead of asserting on something the page shows.

FAQ

What does await do in Playwright?

It waits for the Promise returned by a Playwright call to settle before the next line runs, so actions happen in order.

Does page.goto wait for the page to load?

Yes. By default it waits for the load event. You can change this with the waitUntil option, for example 'domcontentloaded'.

How do I check I am on the right page?

Use await expect(page).toHaveURL(...) or toHaveTitle(...), which retry until they match or time out.

Try it

Practise this in Challenge 1. You write the code in the browser editor with no setup. It runs in a fresh Chromium, a hidden validator checks what actually happened, and you get pass or fail, the logs and a video of the run. Challenges 1 to 10 are open without an account; create a free one any time to keep your progress. The reference solution and the hidden validator are shown only after you pass. We never publish solutions here.