0
0
Testing Fundamentalstesting~10 mins

Test case writing in Testing Fundamentals - Test Execution Trace

Choose your learning style9 modes available
Test Overview

This test case checks if the login form accepts valid user credentials and successfully logs the user in by verifying the presence of a welcome message.

Test Code - Selenium with Python unittest
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_valid_login(self):
        driver = self.driver
        # Find username field and enter username
        username_field = WebDriverWait(driver, 10).until(
            EC.presence_of_element_located((By.ID, 'username'))
        )
        username_field.send_keys('validUser')

        # Find password field and enter password
        password_field = driver.find_element(By.ID, 'password')
        password_field.send_keys('validPass123')

        # Find and click login button
        login_button = driver.find_element(By.ID, 'loginBtn')
        login_button.click()

        # Wait for welcome message to appear
        welcome_message = WebDriverWait(driver, 10).until(
            EC.presence_of_element_located((By.ID, 'welcomeMsg'))
        )

        # Assert welcome message text
        self.assertEqual(welcome_message.text, 'Welcome, validUser!')

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

if __name__ == '__main__':
    unittest.main()
Execution Trace - 6 Steps
StepActionSystem StateAssertionResult
1Test starts and Chrome browser opensBrowser is open at 'https://example.com/login' page showing login form with username, password fields and login button-PASS
2Find username input field by ID 'username' and enter 'validUser'Username field is filled with 'validUser'-PASS
3Find password input field by ID 'password' and enter 'validPass123'Password field is filled with 'validPass123'-PASS
4Find login button by ID 'loginBtn' and click itLogin button clicked, page starts processing login-PASS
5Wait for welcome message element with ID 'welcomeMsg' to appearWelcome message element is visible on pageCheck that welcome message text equals 'Welcome, validUser!'PASS
6Test ends and browser closesBrowser window closed-PASS
Failure Scenario
Failing Condition: Welcome message element does not appear or text does not match expected after login
Execution Trace Quiz - 3 Questions
Test your understanding
What does the test verify after clicking the login button?
AThat the login button disappears
BThat the welcome message with correct text appears
CThat the username field is cleared
DThat the password field becomes visible
Key Result
Always write test cases that clearly describe the steps and expected results, including waiting for elements to appear before asserting, to avoid flaky tests.