0
0
Testing Fundamentalstesting~10 mins

User story testing in Testing Fundamentals - Test Execution Trace

Choose your learning style9 modes available
Test Overview

This test checks if the login feature works as described in the user story. It verifies that a user can enter valid credentials and successfully log in to the application.

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

    def test_valid_login(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('validUser')
        password_input.send_keys('validPass123')
        login_button.click()

        # Wait for dashboard page to load
        WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.ID, 'dashboard')))
        dashboard = driver.find_element(By.ID, 'dashboard')

        self.assertTrue(dashboard.is_displayed(), 'Dashboard should be visible after login')

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

if __name__ == '__main__':
    unittest.main()
Execution Trace - 8 Steps
StepActionSystem StateAssertionResult
1Test starts and opens Chrome browserBrowser opens at 'https://example.com/login' showing login page with username, password fields and login button-PASS
2Waits for username input field to be presentLogin page fully loaded with username input visiblePresence of element with ID 'username'PASS
3Finds username, password inputs and login buttonAll three elements found on the page-PASS
4Enters 'validUser' in username and 'validPass123' in password fieldsInput fields filled with valid credentials-PASS
5Clicks the login buttonLogin request sent, page starts loading dashboard-PASS
6Waits for dashboard element to be presentDashboard page loaded with element ID 'dashboard' visiblePresence of element with ID 'dashboard'PASS
7Checks if dashboard is displayedDashboard visible on screendashboard.is_displayed() returns TruePASS
8Test ends and browser closesBrowser closed-PASS
Failure Scenario
Failing Condition: Dashboard element does not appear after login attempt
Execution Trace Quiz - 3 Questions
Test your understanding
What does the test verify after clicking the login button?
AThat an error message appears
BThat the dashboard page is displayed
CThat the login button is disabled
DThat the username field is cleared
Key Result
Always wait explicitly for key page elements after actions like login to ensure the page has loaded before checking results. This avoids flaky tests.