Test Overview
This test checks if the login feature works as described in the user story. It verifies that a user can enter valid credentials and successfully log in to the application.
This test checks if the login feature works as described in the user story. It verifies that a user can enter valid credentials and successfully log in to the application.
import unittest 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 class TestLoginUserStory(unittest.TestCase): def setUp(self): self.driver = webdriver.Chrome() self.driver.get('https://example.com/login') def test_valid_login(self): driver = self.driver # Wait for username field WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.ID, 'username'))) username_input = driver.find_element(By.ID, 'username') password_input = driver.find_element(By.ID, 'password') login_button = driver.find_element(By.ID, 'login-btn') username_input.send_keys('validUser') password_input.send_keys('validPass123') login_button.click() # Wait for dashboard page to load WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.ID, 'dashboard'))) dashboard = driver.find_element(By.ID, 'dashboard') self.assertTrue(dashboard.is_displayed(), 'Dashboard should be visible after login') def tearDown(self): self.driver.quit() if __name__ == '__main__': unittest.main()
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Test starts and opens Chrome browser | Browser opens at 'https://example.com/login' showing login page with username, password fields and login button | - | PASS |
| 2 | Waits for username input field to be present | Login page fully loaded with username input visible | Presence of element with ID 'username' | PASS |
| 3 | Finds username, password inputs and login button | All three elements found on the page | - | PASS |
| 4 | Enters 'validUser' in username and 'validPass123' in password fields | Input fields filled with valid credentials | - | PASS |
| 5 | Clicks the login button | Login request sent, page starts loading dashboard | - | PASS |
| 6 | Waits for dashboard element to be present | Dashboard page loaded with element ID 'dashboard' visible | Presence of element with ID 'dashboard' | PASS |
| 7 | Checks if dashboard is displayed | Dashboard visible on screen | dashboard.is_displayed() returns True | PASS |
| 8 | Test ends and browser closes | Browser closed | - | PASS |