Test Overview
This test simulates running an automated UI test that fails due to a changed element locator. It verifies that the test detects the missing element and reports a failure, highlighting a common maintenance challenge in automation.
This test simulates running an automated UI test that fails due to a changed element locator. It verifies that the test detects the missing element and reports a failure, highlighting a common maintenance challenge in automation.
from selenium import webdriver from selenium.webdriver.common.by import By from selenium.common.exceptions import NoSuchElementException import unittest class TestLoginButton(unittest.TestCase): def setUp(self): self.driver = webdriver.Chrome() self.driver.get('https://example.com/login') def test_click_login_button(self): driver = self.driver try: login_button = driver.find_element(By.ID, 'login-btn') login_button.click() self.assertTrue(True) # If click succeeds, test passes except NoSuchElementException: self.fail('Login button not found - locator may be outdated') 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 window opened at https://example.com/login page | - | PASS |
| 2 | Test tries to find element with ID 'login-btn' | Page loaded but element with ID 'login-btn' is missing or changed | Check if element with ID 'login-btn' is present | FAIL |
| 3 | NoSuchElementException caught, test fails with message | Test framework records failure due to missing element | Fail test with message 'Login button not found - locator may be outdated' | FAIL |
| 4 | Browser closes and test ends | Browser window closed | - | PASS |