0
0
Testing Fundamentalstesting~10 mins

Why testing prevents costly failures in Testing Fundamentals - Test Execution Impact

Choose your learning style9 modes available
Test Overview

This test simulates checking a simple login form to ensure the system catches errors early. It verifies that the login button is clickable and that an error message appears when invalid credentials are entered. This helps prevent costly failures by catching issues before release.

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 TestLoginForm(unittest.TestCase):
    def setUp(self):
        self.driver = webdriver.Chrome()
        self.driver.get('https://example.com/login')

    def test_invalid_login_shows_error(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')
        password_input = driver.find_element(By.ID, 'password')
        login_button = driver.find_element(By.ID, 'login-btn')

        username_input.send_keys('wronguser')
        password_input.send_keys('wrongpass')
        login_button.click()

        # Wait for error message
        error = WebDriverWait(driver, 10).until(
            EC.visibility_of_element_located((By.ID, 'error-msg'))
        )
        self.assertTrue(error.is_displayed())
        self.assertEqual(error.text, 'Invalid username or password.')

    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' showing login form with username, password fields and login button-PASS
2Waits until username input field is presentUsername input field is visible and ready for inputPresence of element with ID 'username'PASS
3Finds username, password inputs and login button elementsAll three elements found on the page-PASS
4Enters invalid username and passwordUsername field contains 'wronguser', password field contains 'wrongpass'-PASS
5Clicks the login buttonLogin form submits and page processes login attempt-PASS
6Waits for error message to appearError message element with ID 'error-msg' becomes visibleVisibility of element with ID 'error-msg'PASS
7Checks that error message is displayed and text matches expectedError message shown: 'Invalid username or password.'error.is_displayed() is True and error.text equals 'Invalid username or password.'PASS
8Test ends and browser closesBrowser window closes-PASS
Failure Scenario
Failing Condition: Error message does not appear after submitting invalid credentials
Execution Trace Quiz - 3 Questions
Test your understanding
What does the test verify after clicking the login button?
AThat the user is redirected to the homepage
BThat an error message appears for invalid login
CThat the login button becomes disabled
DThat the password field is cleared
Key Result
Testing early by verifying error messages on invalid input helps catch issues before release, preventing costly failures in production.