Test Overview
This test opens a browser using Selenium with pytest, navigates to a website, checks the page title, and verifies it matches the expected title.
This test opens a browser using Selenium with pytest, navigates to a website, checks the page title, and verifies it matches the expected title.
import pytest from selenium import webdriver from selenium.webdriver.chrome.service import Service from selenium.webdriver.common.by import By from selenium.webdriver.chrome.options import Options @pytest.fixture def driver(): options = Options() options.add_argument('--headless') service = Service() driver = webdriver.Chrome(service=service, options=options) yield driver driver.quit() def test_page_title(driver): driver.get('https://example.com') title = driver.title assert title == 'Example Domain', f"Expected title to be 'Example Domain' but got '{title}'"
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Pytest starts and sets up the Chrome WebDriver with headless option | Chrome browser instance is created but not visible (headless mode) | - | PASS |
| 2 | Browser navigates to 'https://example.com' | Browser loads the Example Domain webpage | - | PASS |
| 3 | Test retrieves the page title using driver.title | Page title is 'Example Domain' | Check if page title equals 'Example Domain' | PASS |
| 4 | Assertion verifies the page title matches expected | Title matches expected string | assert title == 'Example Domain' | PASS |
| 5 | Browser quits and test ends | Browser instance closed | - | PASS |