Test Overview
This test checks if a login button is clickable and leads to the dashboard page. It verifies the button presence and page navigation to catch flaky behavior caused by timing or element loading issues.
This test checks if a login button is clickable and leads to the dashboard page. It verifies the button presence and page navigation to catch flaky behavior caused by timing or element loading issues.
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 TestLoginButton(unittest.TestCase): def setUp(self): self.driver = webdriver.Chrome() self.driver.get('https://example.com/login') def test_login_button_click(self): driver = self.driver wait = WebDriverWait(driver, 10) # Wait until login button is clickable to avoid flaky failure login_button = wait.until(EC.element_to_be_clickable((By.ID, 'login-btn'))) login_button.click() # Wait for dashboard page element to confirm navigation dashboard_header = wait.until(EC.presence_of_element_located((By.ID, 'dashboard-header'))) self.assertTrue(dashboard_header.is_displayed()) 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 is open at 'https://example.com/login' page | - | PASS |
| 2 | Wait until login button with ID 'login-btn' is clickable | Login page fully loaded, login button visible and enabled | Check that login button is clickable | PASS |
| 3 | Click the login button | Login button clicked, browser navigates to dashboard page | - | PASS |
| 4 | Wait until dashboard header with ID 'dashboard-header' is present | Dashboard page loaded with header element visible | Verify dashboard header is displayed | PASS |
| 5 | Test ends and browser closes | Browser closed, test complete | - | PASS |