0
0
Testing Fundamentalstesting~10 mins

Root cause analysis in Testing Fundamentals - Test Execution Trace

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

Test Code - Selenium
Testing Fundamentals
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()
Execution Trace - 8 Steps
StepActionSystem StateAssertionResult
1Test starts and opens Chrome browserBrowser window opens at 'https://example.com/login' page-PASS
2Waits for username input field to be presentLogin page loaded with username input visiblePresence of element with ID 'username'PASS
3Finds username input and enters 'validUser'Username field filled with 'validUser'-PASS
4Waits for password input field to be presentPassword input field visible on login pagePresence of element with ID 'password'PASS
5Finds password input and enters 'validPass'Password field filled with 'validPass'-PASS
6Finds and clicks the login buttonLogin button clicked, form submitted-PASS
7Waits for welcome message element to appearPage attempts to load welcome message with ID 'welcomeMsg'Presence of element with ID 'welcomeMsg'FAIL
8Assertion to check welcome message text 'Welcome validUser!'No welcome message found, test cannot verify textwelcome_message.text == 'Welcome validUser!'FAIL
Failure Scenario
Failing Condition: The welcome message element with ID 'welcomeMsg' does not appear after login
Execution Trace Quiz - 3 Questions
Test your understanding
At which step did the test first fail?
AClicking the login button
BEntering the password
CWaiting for the welcome message element
DOpening the browser
Key Result
Root cause analysis helps pinpoint the exact step and reason for failure, enabling focused debugging and faster fixes.