0
0
Testing Fundamentalstesting~10 mins

Why test design drives efficiency in Testing Fundamentals - Test Execution Impact

Choose your learning style9 modes available
Test Overview

This test checks how well a simple login form works by using a well-planned test design. It verifies that the login succeeds with correct data and fails with wrong data, showing how good test design saves time and effort.

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

    def test_login(self):
        driver = self.driver
        # Test data from designed test cases
        test_cases = [
            {'username': 'user1', 'password': 'pass1', 'should_pass': True},
            {'username': 'user1', 'password': 'wrongpass', 'should_pass': False}
        ]
        for case in test_cases:
            username_input = WebDriverWait(driver, 10).until(
                EC.presence_of_element_located((By.ID, 'username'))
            )
            password_input = driver.find_element(By.ID, 'password')
            login_button = driver.find_element(By.ID, 'login-btn')

            username_input.clear()
            username_input.send_keys(case['username'])
            password_input.clear()
            password_input.send_keys(case['password'])
            login_button.click()

            if case['should_pass']:
                welcome_msg = WebDriverWait(driver, 10).until(
                    EC.presence_of_element_located((By.ID, 'welcome-msg'))
                )
                self.assertIn('Welcome', welcome_msg.text)
            else:
                error_msg = WebDriverWait(driver, 10).until(
                    EC.presence_of_element_located((By.ID, 'error-msg'))
                )
                self.assertIn('Invalid', error_msg.text)

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

if __name__ == '__main__':
    unittest.main()
Execution Trace - 7 Steps
StepActionSystem StateAssertionResult
1Test starts and opens Chrome browserBrowser opens at https://example.com/login showing login form with username, password fields and login button-PASS
2Find username, password input fields and login buttonLogin form elements are present and interactableCheck presence of username input fieldPASS
3Enter username 'user1' and password 'pass1', then click loginLogin form filled with valid credentials and login button clicked-PASS
4Wait for welcome message to appearPage shows welcome message with text containing 'Welcome'Verify welcome message text contains 'Welcome'PASS
5Clear inputs, enter username 'user1' and wrong password 'wrongpass', then click loginLogin form filled with invalid credentials and login button clicked-PASS
6Wait for error message to appearPage shows error message with text containing 'Invalid'Verify error message text contains 'Invalid'PASS
7Close browser and end testBrowser closed-PASS
Failure Scenario
Failing Condition: If the login page elements are missing or the messages do not appear as expected
Execution Trace Quiz - 3 Questions
Test your understanding
What does the test verify after entering correct login details?
AThat the login button is disabled
BThat an error message appears containing 'Invalid'
CThat a welcome message appears containing 'Welcome'
DThat the page URL changes to /error
Key Result
Good test design selects key input cases to cover important behaviors, reducing test time and improving clarity.