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.
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.
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()
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Test starts and opens Chrome browser | Browser window opens at 'https://example.com/login' showing login form with username and password fields | - | PASS |
| 2 | Find username and password input fields and enter valid credentials | Username field filled with 'validUser', password field filled with 'validPass123' | - | PASS |
| 3 | Find and click the login button | Login button clicked, page starts loading the user dashboard | - | PASS |
| 4 | Wait for welcome message element to appear | Welcome message element with id 'welcome-msg' appears on the page | Check that welcome message text equals 'Welcome, validUser!' | PASS |
| 5 | Close the browser and end test | Browser window closes | - | PASS |