Playwright + Python · Lesson 18 of 37
Module 18: Assertions
Your task
Implement verify_dashboard_elements(page, expected_url):
Write it in the editor, then press Check answer (Ctrl + Enter).
from playwright.sync_api import expect
expect(page).to_have_url("https://targetqa.com/dashboard")
expect(page).to_have_title("Dashboard - TargetQA")
welcome_msg = page.get_by_role("heading")
expect(welcome_msg).to_be_visible()
expect(welcome_msg).to_have_text("Welcome back!")Web-first assertions are Playwright's most effective weapon against flakiness. The expect() function re-polls the DOM until the condition passes or timeout occurs. In this lesson, you will master to_be_visible, to_have_text, and to_have_url. Let's master assertions!
Part of the Playwright + Python course (Playwright with Python). Practice this concept live in the Playwright Online Compiler or explore our free automation practice form.
locator.is_visible() evaluates immediately once without retrying. expect(locator).to_be_visible() continuously polls until true.
Ready? Solve the task in the editor
Use Check answer to mark it complete. Hints are there if you need them.
___