0
0
Testing Fundamentalstesting~10 mins

Automation maintenance challenges in Testing Fundamentals - Test Execution Trace

Choose your learning style9 modes available
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.

Test Code - Selenium with unittest
Testing Fundamentals
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()
Execution Trace - 4 Steps
StepActionSystem StateAssertionResult
1Test starts and Chrome browser opensBrowser window opened at https://example.com/login page-PASS
2Test tries to find element with ID 'login-btn'Page loaded but element with ID 'login-btn' is missing or changedCheck if element with ID 'login-btn' is presentFAIL
3NoSuchElementException caught, test fails with messageTest framework records failure due to missing elementFail test with message 'Login button not found - locator may be outdated'FAIL
4Browser closes and test endsBrowser window closed-PASS
Failure Scenario
Failing Condition: The element locator 'login-btn' is outdated or changed in the application UI
Execution Trace Quiz - 3 Questions
Test your understanding
What caused the test to fail in the execution trace?
AThe element with ID 'login-btn' was not found on the page
BThe browser failed to open the URL
CThe test assertion was incorrect
DThe test code had a syntax error
Key Result
Automated tests often fail when UI elements change. Regularly updating locators and maintaining tests is essential to keep automation reliable.