Test Overview
This test checks if a user can successfully log in with valid credentials and verifies that the welcome message appears after login.
This test checks if a user can successfully log in with valid credentials and verifies that the welcome message appears after login.
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 TestAuthentication(unittest.TestCase): def setUp(self): self.driver = webdriver.Chrome() self.driver.get('https://example.com/login') def test_valid_login(self): driver = self.driver username_input = WebDriverWait(driver, 10).until( EC.presence_of_element_located((By.ID, 'username')) ) username_input.send_keys('validUser') password_input = driver.find_element(By.ID, 'password') password_input.send_keys('validPass123') login_button = driver.find_element(By.ID, 'login-button') login_button.click() welcome_message = WebDriverWait(driver, 10).until( EC.visibility_of_element_located((By.ID, 'welcome-msg')) ) self.assertEqual(welcome_message.text, 'Welcome, validUser!') 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 window opens at 'https://example.com/login' showing login form with username and password fields | - | PASS |
| 2 | Waits for username input field to be present and enters 'validUser' | Username input field is visible and filled with 'validUser' | - | PASS |
| 3 | Finds password input field and enters 'validPass123' | Password input field is visible and filled with 'validPass123' | - | PASS |
| 4 | Finds and clicks the login button | Login button clicked, page starts loading user dashboard | - | PASS |
| 5 | Waits for welcome message to be visible | Welcome message element with text 'Welcome, validUser!' is visible on the page | Check that welcome message text equals 'Welcome, validUser!' | PASS |
| 6 | Test ends and browser closes | Browser window closes | - | PASS |