0
0
PyTesttesting~10 mins

Single responsibility per test in PyTest - Test Execution Trace

Choose your learning style9 modes available
Test Overview

This test checks that the login page accepts valid credentials and shows a welcome message. It focuses on one clear action: successful login.

Test Code - pytest
PyTest
import pytest
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

def test_successful_login():
    driver = webdriver.Chrome()
    driver.get('https://example.com/login')

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

    welcome_message = WebDriverWait(driver, 10).until(
        EC.presence_of_element_located((By.ID, 'welcome-msg'))
    )

    assert welcome_message.text == 'Welcome, validUser!'
    driver.quit()
Execution Trace - 9 Steps
StepActionSystem StateAssertionResult
1Test starts and Chrome browser opensBrowser window is open, ready to navigate-PASS
2Navigates to 'https://example.com/login'Login page is loaded with username, password fields and login button-PASS
3Waits for username input field to be presentUsername input field is visible and interactablePresence of username input fieldPASS
4Finds password input and login button elementsPassword input and login button are visible-PASS
5Types 'validUser' into username and 'validPass123' into passwordInput fields contain the correct text-PASS
6Clicks the login buttonForm submitted, page starts loading next content-PASS
7Waits for welcome message element to appearWelcome message is visible on the pagePresence of welcome message elementPASS
8Checks that welcome message text equals 'Welcome, validUser!'Welcome message text is exactly as expectedwelcome_message.text == 'Welcome, validUser!'PASS
9Closes the browser and ends the testBrowser closed, test finished-PASS
Failure Scenario
Failing Condition: Welcome message does not appear or text is incorrect after login
Execution Trace Quiz - 3 Questions
Test your understanding
What is the main focus of this test?
ACheck password field validation
BVerify successful login shows welcome message
CTest logout functionality
DVerify page title on login page
Key Result
Each test should focus on one clear behavior or feature to keep tests simple and easy to understand. This makes failures easier to diagnose.