Test Overview
This test checks that the login page accepts valid credentials and shows a welcome message. It focuses on one clear action: successful login.
This test checks that the login page accepts valid credentials and shows a welcome message. It focuses on one clear action: successful login.
import pytest 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 def test_successful_login(): driver = webdriver.Chrome() driver.get('https://example.com/login') username_input = WebDriverWait(driver, 10).until( EC.presence_of_element_located((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() welcome_message = WebDriverWait(driver, 10).until( EC.presence_of_element_located((By.ID, 'welcome-msg')) ) assert welcome_message.text == 'Welcome, validUser!' driver.quit()
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Test starts and Chrome browser opens | Browser window is open, ready to navigate | - | PASS |
| 2 | Navigates to 'https://example.com/login' | Login page is loaded with username, password fields and login button | - | PASS |
| 3 | Waits for username input field to be present | Username input field is visible and interactable | Presence of username input field | PASS |
| 4 | Finds password input and login button elements | Password input and login button are visible | - | PASS |
| 5 | Types 'validUser' into username and 'validPass123' into password | Input fields contain the correct text | - | PASS |
| 6 | Clicks the login button | Form submitted, page starts loading next content | - | PASS |
| 7 | Waits for welcome message element to appear | Welcome message is visible on the page | Presence of welcome message element | PASS |
| 8 | Checks that welcome message text equals 'Welcome, validUser!' | Welcome message text is exactly as expected | welcome_message.text == 'Welcome, validUser!' | PASS |
| 9 | Closes the browser and ends the test | Browser closed, test finished | - | PASS |