0
0
Testing Fundamentalstesting~10 mins

Behavior-driven development (BDD) concept in Testing Fundamentals - Test Execution Trace

Choose your learning style9 modes available
Test Overview

This test checks a simple login feature using Behavior-driven development (BDD). It verifies that when a user enters correct credentials, they successfully log in and see a welcome message.

Test Code - Behave with Selenium
Testing Fundamentals
from behave import given, when, then
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

@given('the user is on the login page')
def step_impl(context):
    context.driver = webdriver.Chrome()
    context.driver.get('https://example.com/login')

@when('the user enters valid username and password')
def step_impl(context):
    username_input = context.driver.find_element(By.ID, 'username')
    password_input = context.driver.find_element(By.ID, 'password')
    username_input.send_keys('validUser')
    password_input.send_keys('validPass123')
    login_button = context.driver.find_element(By.ID, 'login-btn')
    login_button.click()

@then('the user should see the welcome message')
def step_impl(context):
    WebDriverWait(context.driver, 10).until(
        EC.presence_of_element_located((By.ID, 'welcome-msg'))
    )
    welcome_text = context.driver.find_element(By.ID, 'welcome-msg').text
    assert welcome_text == 'Welcome, validUser!'
    context.driver.quit()
Execution Trace - 5 Steps
StepActionSystem StateAssertionResult
1Test starts and opens Chrome browserBrowser window opens at 'https://example.com/login' showing login form with username and password fields-PASS
2Find username and password input fields and enter valid credentialsUsername field filled with 'validUser', password field filled with 'validPass123'-PASS
3Find and click the login buttonLogin button clicked, page starts loading the user dashboard-PASS
4Wait for welcome message element to appearWelcome message element with id 'welcome-msg' appears on the pageCheck that welcome message text equals 'Welcome, validUser!'PASS
5Close the browser and end testBrowser window closes-PASS
Failure Scenario
Failing Condition: Welcome message element does not appear or text is incorrect after login
Execution Trace Quiz - 3 Questions
Test your understanding
What does the test verify after clicking the login button?
AThat the login button is disabled
BThat the welcome message with correct text appears
CThat the username field is cleared
DThat the password is visible
Key Result
BDD tests use simple language to describe user behavior, making tests easy to read and understand by both technical and non-technical team members.