“Don’t read about testing. Do the testing.”
Here’s your fast-track to firing your first Selenium test with Python & Pytest.
🚀 TL;DR
- Setup ChromeDriver
- Add some WebDriver options
- Write a Pytest test
- ✅ Profit
pip install selenium pytest
📦 Setup
from selenium import webdriver
import pytest
@pytest.fixture
def driver():
options = webdriver.ChromeOptions()
options.add_argument('--headless')
driver = webdriver.Chrome(options=options)
yield driver
driver.quit()
🧪 First Test
def test_page_load_and_title(driver):
driver.get("https://www.example.com")
assert "Example Domain" in driver.title
💡 Gotchas
- Always use
yield
in fixture, or you’ll get ghost browsers haunting your RAM. - Use
--headless
for CI pipelines (no GUI). - Selenium tests = real browser = real slow → use sparingly.
🔍 Want More?
Feeling curious or confused? Jump into the deep dives:
Stay sharp, test sharper. 🔪