SeleniumLab

Course1 · Selenium automation → Assertions & Structure

1 · Selenium automation

Assertions that catch regressions

10 min · Module 10

Automation is only useful when it fails for the right reasons. Assert titles, texts, counts, and URLs.

Example / notes

from selenium import webdriver
from selenium.webdriver.common.by import By

driver = webdriver.Chrome()
driver.get("http://127.0.0.1:8000/lab/table/")

assert "Team Directory" in driver.find_element(By.ID, "table-heading").text
rows = driver.find_elements(By.CSS_SELECTOR, "[data-testid='employee-row']")
assert len(rows) == 5
statuses = [r.find_element(By.CSS_SELECTOR, "[data-testid='cell-status']").text for r in rows]
assert "Active" in statuses
driver.quit()

Practice in Lab: /lab/table/

Log in to track progress / take quizzes
Organizing tests with pytest →
Modules in this track