0
0
Testing Fundamentalstesting~15 mins

Acceptance criteria verification in Testing Fundamentals - Build an Automation Script

Choose your learning style9 modes available
Verify acceptance criteria for user login functionality
Preconditions (2)
Step 1: Enter 'user@example.com' in the email input field
Step 2: Enter 'Password123' in the password input field
Step 3: Click the 'Login' button
✅ Expected Result: User is redirected to the dashboard page with URL containing '/dashboard' and a welcome message 'Welcome, user!' is displayed
Automation Requirements - Selenium with Python
Assertions Needed:
Verify current URL contains '/dashboard'
Verify welcome message text is 'Welcome, user!'
Best Practices:
Use explicit waits to wait for elements to be visible
Use By.ID or By.CSS_SELECTOR for locating elements
Use Page Object Model pattern for maintainability
Automated Solution
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

class LoginPage:
    def __init__(self, driver):
        self.driver = driver
        self.email_input = (By.ID, 'email')
        self.password_input = (By.ID, 'password')
        self.login_button = (By.ID, 'login-btn')

    def enter_email(self, email):
        WebDriverWait(self.driver, 10).until(EC.visibility_of_element_located(self.email_input)).send_keys(email)

    def enter_password(self, password):
        WebDriverWait(self.driver, 10).until(EC.visibility_of_element_located(self.password_input)).send_keys(password)

    def click_login(self):
        WebDriverWait(self.driver, 10).until(EC.element_to_be_clickable(self.login_button)).click()

class DashboardPage:
    def __init__(self, driver):
        self.driver = driver
        self.welcome_message = (By.ID, 'welcome-msg')

    def get_welcome_text(self):
        return WebDriverWait(self.driver, 10).until(EC.visibility_of_element_located(self.welcome_message)).text


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

    login_page = LoginPage(driver)
    login_page.enter_email('user@example.com')
    login_page.enter_password('Password123')
    login_page.click_login()

    WebDriverWait(driver, 10).until(EC.url_contains('/dashboard'))
    assert '/dashboard' in driver.current_url, 'URL does not contain /dashboard'

    dashboard_page = DashboardPage(driver)
    welcome_text = dashboard_page.get_welcome_text()
    assert welcome_text == 'Welcome, user!', f'Unexpected welcome message: {welcome_text}'

    driver.quit()

This test script uses Selenium with Python to automate the acceptance criteria verification for the login functionality.

We define two page classes: LoginPage and DashboardPage to organize locators and actions, following the Page Object Model pattern for maintainability.

Explicit waits ensure the script waits for elements to be visible or clickable before interacting, avoiding flaky tests.

The test navigates to the login page, enters the provided email and password, clicks login, then waits for the URL to contain '/dashboard'. It asserts the URL and the welcome message text to verify acceptance criteria.

Finally, the browser is closed with driver.quit() to clean up.

Common Mistakes - 3 Pitfalls
{'mistake': 'Using time.sleep() instead of explicit waits', 'why_bad': 'It causes tests to wait unnecessarily long or fail if elements load slower or faster than expected.', 'correct_approach': "Use Selenium's explicit waits like WebDriverWait with expected_conditions to wait only as long as needed."}
Using brittle XPath locators with absolute paths
Not verifying both URL and page content
Bonus Challenge

Now add data-driven testing with 3 different sets of valid user credentials

Show Hint