Test Overview
This test simulates a user logging into a website using a valid username and password. It verifies that the login is successful and the user is redirected to the dashboard page.
This test simulates a user logging into a website using a valid username and password. It verifies that the login is successful and the user is redirected to the dashboard page.
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 TestLoginUseCase(unittest.TestCase): def setUp(self): self.driver = webdriver.Chrome() self.driver.get('https://example.com/login') def test_valid_login(self): driver = self.driver # Find username field and enter username username_field = WebDriverWait(driver, 10).until( EC.presence_of_element_located((By.ID, 'username')) ) username_field.send_keys('validUser') # Find password field and enter password password_field = driver.find_element(By.ID, 'password') password_field.send_keys('validPass123') # Find and click login button login_button = driver.find_element(By.ID, 'loginBtn') login_button.click() # Wait for dashboard page to load by checking for dashboard element dashboard_element = WebDriverWait(driver, 10).until( EC.presence_of_element_located((By.ID, 'dashboard')) ) # Assert dashboard element is displayed self.assertTrue(dashboard_element.is_displayed()) def tearDown(self): self.driver.quit() if __name__ == '__main__': unittest.main()
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Test starts and browser opens | Browser window opens at 'https://example.com/login' page | - | PASS |
| 2 | Waits for username field to be present and enters 'validUser' | Login page shows username input field with id 'username' | Username field is present and ready for input | PASS |
| 3 | Finds password field and enters 'validPass123' | Password input field with id 'password' is visible | Password field is present and ready for input | PASS |
| 4 | Finds and clicks the login button with id 'loginBtn' | Login button is clickable on the login page | Login button is present and clickable | PASS |
| 5 | Waits for dashboard element with id 'dashboard' to appear after login | Browser navigates to dashboard page showing element with id 'dashboard' | Dashboard element is present and displayed | PASS |
| 6 | Asserts that dashboard element is displayed | Dashboard page fully loaded and visible | dashboard_element.is_displayed() returns True | PASS |
| 7 | Test ends and browser closes | Browser window closes | - | PASS |