Bird
Raised Fist0
Testing Fundamentalstesting~15 mins

Acceptance criteria verification in Testing Fundamentals - Build an Automation Script

Choose your learning style10 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

Practice

(1/5)
1. What is the main purpose of acceptance criteria in software testing?
easy
A. To write code for the feature
B. To define what 'done' means for a feature
C. To design the user interface
D. To create test automation scripts

Solution

  1. Step 1: Understand acceptance criteria role

    Acceptance criteria specify the conditions that must be met for a feature to be considered complete.
  2. Step 2: Differentiate from other tasks

    Writing code, designing UI, and creating automation are separate activities, not the main purpose of acceptance criteria.
  3. Final Answer:

    To define what 'done' means for a feature -> Option B
  4. Quick Check:

    Acceptance criteria = Definition of done [OK]
Hint: Acceptance criteria define 'done' clearly [OK]
Common Mistakes:
  • Confusing acceptance criteria with coding tasks
  • Thinking acceptance criteria are test scripts
  • Mixing acceptance criteria with UI design
2. Which of the following is the correct way to write an acceptance criterion?
easy
A. Users might be able to reset passwords sometimes.
B. Reset password feature is cool and works well.
C. The system shall allow users to reset their password via email.
D. Password reset should be fast and secure.

Solution

  1. Step 1: Identify clear, testable criteria

    The system shall allow users to reset their password via email. clearly states a specific, testable behavior: users can reset passwords via email.
  2. Step 2: Evaluate other options for clarity and testability

    The other options are vague or subjective and cannot be directly tested.
  3. Final Answer:

    The system shall allow users to reset their password via email. -> Option C
  4. Quick Check:

    Clear and testable = The system shall allow users to reset their password via email. [OK]
Hint: Look for clear, testable statements [OK]
Common Mistakes:
  • Choosing vague or subjective statements
  • Ignoring testability of criteria
  • Confusing feature description with acceptance criteria
3. Given the acceptance criterion: The login button must be disabled until both username and password fields are filled. Which test case will verify this criterion correctly?
medium
A. Check if login button is disabled when username is filled but password is empty.
B. Check if login button is enabled when both fields are empty.
C. Check if login button is disabled when both fields are filled.
D. Check if login button is enabled when username is filled but password is empty.

Solution

  1. Step 1: Understand the criterion condition

    The login button should be disabled until both fields have values.
  2. Step 2: Identify the correct test case

    Check if login button is disabled when username is filled but password is empty. tests that the button is disabled when only username is filled, which matches the criterion.
  3. Final Answer:

    Check if login button is disabled when username is filled but password is empty. -> Option A
  4. Quick Check:

    Button disabled until both fields filled = Check if login button is disabled when username is filled but password is empty. [OK]
Hint: Test partial inputs to check button state [OK]
Common Mistakes:
  • Testing button enabled when fields are empty
  • Expecting button disabled when both fields filled
  • Ignoring partial input cases
4. You have this acceptance criterion: The search results must display within 2 seconds after submitting a query. Which of the following is the best way to debug a failing test that shows results after 5 seconds?
medium
A. Check network speed and server response times.
B. Ignore the delay since results eventually appear.
C. Change the acceptance criterion to 5 seconds.
D. Remove the timer from the test case.

Solution

  1. Step 1: Analyze the cause of delay

    Since results take 5 seconds, check network and server performance to find bottlenecks.
  2. Step 2: Avoid ignoring or changing criteria improperly

    Ignoring delay or changing criteria without cause is incorrect; removing timer hides the problem.
  3. Final Answer:

    Check network speed and server response times. -> Option A
  4. Quick Check:

    Debug performance issues first = Check network speed and server response times. [OK]
Hint: Investigate environment before changing criteria [OK]
Common Mistakes:
  • Ignoring the delay problem
  • Changing acceptance criteria without reason
  • Removing test validations
5. A feature has these acceptance criteria:
1. Users can add items to the cart.
2. Cart updates total price correctly.
3. Cart shows an error if quantity exceeds stock.

During testing, you find the cart updates price but does not show an error when quantity is too high. What should you do next?
hard
A. Change acceptance criteria to remove error message requirement.
B. Mark the feature as complete since price updates correctly.
C. Ignore the error message since it is not critical.
D. Report a bug for missing error message and retest after fix.

Solution

  1. Step 1: Verify all acceptance criteria

    The feature meets price update but fails to show error for quantity exceeding stock.
  2. Step 2: Take appropriate action

    Since one criterion fails, report a bug and plan to retest after the fix.
  3. Final Answer:

    Report a bug for missing error message and retest after fix. -> Option D
  4. Quick Check:

    Failing criteria means report bug = Report a bug for missing error message and retest after fix. [OK]
Hint: Failing any criterion means report bug [OK]
Common Mistakes:
  • Ignoring failed criteria
  • Marking incomplete features as done
  • Changing acceptance criteria to hide bugs
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard