Test Overview
This test simulates a simple login functionality check and demonstrates how root cause analysis helps identify the exact reason for a test failure.
This test simulates a simple login functionality check and demonstrates how root cause analysis helps identify the exact reason for a test failure.
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_login_with_valid_credentials(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') username_input.send_keys('validUser') # Wait for password field WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.ID, 'password'))) password_input = driver.find_element(By.ID, 'password') password_input.send_keys('validPass') # Click login button login_button = driver.find_element(By.ID, 'loginBtn') login_button.click() # Wait for welcome message welcome_message = WebDriverWait(driver, 10).until( EC.presence_of_element_located((By.ID, 'welcomeMsg')) ) 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' page | - | PASS |
| 2 | Waits for username input field to be present | Login page loaded with username input visible | Presence of element with ID 'username' | PASS |
| 3 | Finds username input and enters 'validUser' | Username field filled with 'validUser' | - | PASS |
| 4 | Waits for password input field to be present | Password input field visible on login page | Presence of element with ID 'password' | PASS |
| 5 | Finds password input and enters 'validPass' | Password field filled with 'validPass' | - | PASS |
| 6 | Finds and clicks the login button | Login button clicked, form submitted | - | PASS |
| 7 | Waits for welcome message element to appear | Page attempts to load welcome message with ID 'welcomeMsg' | Presence of element with ID 'welcomeMsg' | FAIL |
| 8 | Assertion to check welcome message text 'Welcome validUser!' | No welcome message found, test cannot verify text | welcome_message.text == 'Welcome validUser!' | FAIL |