0
0
Testing Fundamentalstesting~10 mins

Flaky test management in Testing Fundamentals - Test Execution Trace

Choose your learning style9 modes available
Test Overview

This test checks if a login button is clickable and leads to the dashboard page. It verifies the button presence and page navigation to catch flaky behavior caused by timing or element loading issues.

Test Code - Selenium with unittest
Testing Fundamentals
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
import unittest

class TestLoginButton(unittest.TestCase):
    def setUp(self):
        self.driver = webdriver.Chrome()
        self.driver.get('https://example.com/login')

    def test_login_button_click(self):
        driver = self.driver
        wait = WebDriverWait(driver, 10)
        # Wait until login button is clickable to avoid flaky failure
        login_button = wait.until(EC.element_to_be_clickable((By.ID, 'login-btn')))
        login_button.click()
        # Wait for dashboard page element to confirm navigation
        dashboard_header = wait.until(EC.presence_of_element_located((By.ID, 'dashboard-header')))
        self.assertTrue(dashboard_header.is_displayed())

    def tearDown(self):
        self.driver.quit()

if __name__ == '__main__':
    unittest.main()
Execution Trace - 5 Steps
StepActionSystem StateAssertionResult
1Test starts and Chrome browser opensBrowser is open at 'https://example.com/login' page-PASS
2Wait until login button with ID 'login-btn' is clickableLogin page fully loaded, login button visible and enabledCheck that login button is clickablePASS
3Click the login buttonLogin button clicked, browser navigates to dashboard page-PASS
4Wait until dashboard header with ID 'dashboard-header' is presentDashboard page loaded with header element visibleVerify dashboard header is displayedPASS
5Test ends and browser closesBrowser closed, test complete-PASS
Failure Scenario
Failing Condition: Login button is not clickable within 10 seconds due to slow page load or overlay blocking it
Execution Trace Quiz - 3 Questions
Test your understanding
What does the test wait for before clicking the login button?
AThe dashboard header to be visible
BThe login button to be clickable
CThe page title to be 'Dashboard'
DThe login button to be present in the DOM
Key Result
Use explicit waits to ensure elements are ready before interacting. This reduces flaky test failures caused by timing or loading delays.