SoftwareTestPilot

Playwright locators and assertions

  • Playwright
  • intermediate
  • 6 min
  • 2 questions

Flaky Playwright suites usually come from brittle locators and assertions that do not wait. Choose the options that follow Playwright's recommended, auto-waiting style.

Skills practised: Role-based locators, Web-first assertions, Flakiness prevention

Worked example

expect(await page.isVisible('.toast')).toBe(true) checks once. The web-first version retries until the timeout:

await expect(page.getByRole('status')).toBeVisible();

Question 1

Which locator is most resilient for a "Place order" button?

Which locator is most resilient for a "Place order" button?

Question 2

Complete the web-first assertion that checks a heading has the exact text "Order confirmed": await expect(heading).______('Order confirmed')

0/2 answered

Keep learning