Course → 1 · Selenium automation → Assertions & Structure
1 · Selenium automation
Organizing tests with pytest
12 min · Module 10
Use fixtures for driver setup/teardown so each test starts clean. Name tests after the behavior you verify.
Example / notes
# test_login.py
import pytest
from selenium import webdriver
from selenium.webdriver.common.by import By
@pytest.fixture
def driver():
driver = webdriver.Chrome()
yield driver
driver.quit()
def test_valid_login(driver):
driver.get("http://127.0.0.1:8000/lab/login/")
driver.find_element(By.ID, "username").send_keys("demo")
driver.find_element(By.ID, "password").send_keys("demo1234")
driver.find_element(By.ID, "login-button").click()
assert "/lab/welcome/" in driver.current_url
assert driver.find_element(By.ID, "flash-success").is_displayed()
Practice in Lab: /lab/login/
Modules in this track
- 6. Getting Started
- 7. Finding Elements
- 8. Interactions
- 9. Waits
- 10. Assertions & Structure
- 11. Page Object Model
- 12. Alerts, Frames & Windows
- 13. Headless & Next Steps