Test Overview
This test opens a web page using a base page class, finds a button by its ID, clicks it, and verifies the page title changes as expected.
This test opens a web page using a base page class, finds a button by its ID, clicks it, and verifies the page title changes as expected.
from selenium import webdriver from selenium.webdriver.common.by import By from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC import unittest class BasePage: def __init__(self, driver): self.driver = driver def find_element(self, locator): return WebDriverWait(self.driver, 10).until(EC.presence_of_element_located(locator)) def click(self, locator): element = self.find_element(locator) element.click() class TestHomePage(unittest.TestCase): def setUp(self): self.driver = webdriver.Chrome() self.base_page = BasePage(self.driver) def test_click_button_changes_title(self): self.driver.get("https://example.com") button_locator = (By.ID, "start-button") self.base_page.click(button_locator) WebDriverWait(self.driver, 10).until(EC.title_is("Started Page")) self.assertEqual(self.driver.title, "Started Page") def tearDown(self): self.driver.quit() if __name__ == '__main__': unittest.main()
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Test starts and WebDriver Chrome instance is created | Browser window opens, ready to navigate | - | PASS |
| 2 | Browser navigates to https://example.com | Page loads with a button having ID 'start-button' | - | PASS |
| 3 | BasePage finds element with ID 'start-button' using WebDriverWait | Button element is present and visible | Element presence verified by WebDriverWait | PASS |
| 4 | BasePage clicks the 'start-button' | Button is clicked, page starts navigation or changes | - | PASS |
| 5 | Wait until page title changes to 'Started Page' | Page title updates to 'Started Page' | Title is exactly 'Started Page' | PASS |
| 6 | Assert page title equals 'Started Page' | Page title is 'Started Page' | assertEqual passes confirming title | PASS |
| 7 | Test ends and browser closes | Browser window closes | - | PASS |