0
0
Testing Fundamentalstesting~10 mins

Use case testing in Testing Fundamentals - Test Execution Trace

Choose your learning style9 modes available
Test Overview

This test simulates a user logging into a website using a valid username and password. It verifies that the login is successful and the user is redirected to the dashboard page.

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 TestLoginUseCase(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 dashboard page to load by checking for dashboard element
        dashboard_element = WebDriverWait(driver, 10).until(
            EC.presence_of_element_located((By.ID, 'dashboard'))
        )

        # Assert dashboard element is displayed
        self.assertTrue(dashboard_element.is_displayed())

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

if __name__ == '__main__':
    unittest.main()
Execution Trace - 7 Steps
StepActionSystem StateAssertionResult
1Test starts and browser opensBrowser window opens at 'https://example.com/login' page-PASS
2Waits for username field to be present and enters 'validUser'Login page shows username input field with id 'username'Username field is present and ready for inputPASS
3Finds password field and enters 'validPass123'Password input field with id 'password' is visiblePassword field is present and ready for inputPASS
4Finds and clicks the login button with id 'loginBtn'Login button is clickable on the login pageLogin button is present and clickablePASS
5Waits for dashboard element with id 'dashboard' to appear after loginBrowser navigates to dashboard page showing element with id 'dashboard'Dashboard element is present and displayedPASS
6Asserts that dashboard element is displayedDashboard page fully loaded and visibledashboard_element.is_displayed() returns TruePASS
7Test ends and browser closesBrowser window closes-PASS
Failure Scenario
Failing Condition: Dashboard element with id 'dashboard' does not appear within 10 seconds after login
Execution Trace Quiz - 3 Questions
Test your understanding
What does the test verify after clicking the login button?
AThat the login button changes color
BThat the username field is cleared
CThat the dashboard page loads and the dashboard element is visible
DThat an error message appears
Key Result
Use case testing verifies the entire user journey step-by-step, ensuring each action leads to the expected result, just like following a recipe to bake a cake successfully.