Test Overview
This test case checks if the login form accepts valid user credentials and successfully logs the user in by verifying the presence of a welcome message.
This test case checks if the login form accepts valid user credentials and successfully logs the user in by verifying the presence of a welcome message.
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 LoginTest(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 welcome message to appear welcome_message = WebDriverWait(driver, 10).until( EC.presence_of_element_located((By.ID, 'welcomeMsg')) ) # Assert welcome message text 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 Chrome browser opens | Browser is open at 'https://example.com/login' page showing login form with username, password fields and login button | - | PASS |
| 2 | Find username input field by ID 'username' and enter 'validUser' | Username field is filled with 'validUser' | - | PASS |
| 3 | Find password input field by ID 'password' and enter 'validPass123' | Password field is filled with 'validPass123' | - | PASS |
| 4 | Find login button by ID 'loginBtn' and click it | Login button clicked, page starts processing login | - | PASS |
| 5 | Wait for welcome message element with ID 'welcomeMsg' to appear | Welcome message element is visible on page | Check that welcome message text equals 'Welcome, validUser!' | PASS |
| 6 | Test ends and browser closes | Browser window closed | - | PASS |