Test Overview
This test checks if the login page loads correctly and the login button is clickable using a page class structure in Selenium with Python.
This test checks if the login page loads correctly and the login button is clickable using a page class structure in Selenium with Python.
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.url = "https://example.com/login" self.login_button_locator = (By.ID, "login-btn") def load(self): self.driver.get(self.url) def click_login(self): WebDriverWait(self.driver, 10).until( EC.element_to_be_clickable(self.login_button_locator) ).click() class TestLoginPage(unittest.TestCase): def setUp(self): self.driver = webdriver.Chrome() self.login_page = LoginPage(self.driver) def test_login_button_clickable(self): self.login_page.load() self.login_page.click_login() # Verify URL changed or login action started self.assertIn("dashboard", self.driver.current_url) 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 but no page loaded yet | - | PASS |
| 2 | Navigates to https://example.com/login using LoginPage.load() | Login page is loaded in the browser | - | PASS |
| 3 | Waits until login button is clickable and clicks it using LoginPage.click_login() | Login button is clicked, browser navigates to dashboard page | Check if current URL contains 'dashboard' | PASS |
| 4 | Assertion verifies URL contains 'dashboard' | Browser URL is https://example.com/dashboard | self.assertIn("dashboard", self.driver.current_url) | PASS |
| 5 | Test ends and browser closes | Browser window is closed | - | PASS |