Test Overview
This test opens a web page, uses a page class to find a login button by its locator, clicks it, and verifies the next page shows a welcome message.
This test opens a web page, uses a page class to find a login button by its locator, clicks it, and verifies the next page shows a welcome message.
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 LoginPage: def __init__(self, driver): self.driver = driver self.login_button_locator = (By.ID, "login-btn") def click_login(self): login_button = WebDriverWait(self.driver, 10).until( EC.element_to_be_clickable(self.login_button_locator) ) login_button.click() class TestLogin(unittest.TestCase): def setUp(self): self.driver = webdriver.Chrome() self.driver.get("https://example.com/login") def test_click_login_button(self): page = LoginPage(self.driver) page.click_login() welcome_text = WebDriverWait(self.driver, 10).until( EC.visibility_of_element_located((By.ID, "welcome-msg")) ).text self.assertEqual(welcome_text, "Welcome User") def tearDown(self): self.driver.quit() if __name__ == '__main__': unittest.main()
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Test starts and Chrome browser opens | Browser window is open, ready to load URL | - | PASS |
| 2 | Browser navigates to https://example.com/login | Login page is loaded with login button visible | - | PASS |
| 3 | LoginPage object is created with driver | Page class has locator for login button stored | - | PASS |
| 4 | Waits until login button is clickable and clicks it | Login button is clicked, page starts loading next content | - | PASS |
| 5 | Waits until welcome message element is visible | Welcome message element with text 'Welcome User' is visible | Check that welcome message text equals 'Welcome User' | PASS |
| 6 | Test ends and browser closes | Browser window is closed | - | PASS |