0
0
Testing Fundamentalstesting~15 mins

Tool selection criteria in Testing Fundamentals - Build an Automation Script

Choose your learning style9 modes available
Verify tool selection criteria checklist functionality
Preconditions (1)
Step 1: Locate the checklist section on the page
Step 2: Verify that all expected criteria items are listed: 'Cost', 'Ease of Use', 'Integration', 'Support', 'Features'
Step 3: Check the checkbox for 'Cost'
Step 4: Check the checkbox for 'Ease of Use'
Step 5: Uncheck the checkbox for 'Cost'
Step 6: Click the 'Submit' button
Step 7: Verify that a confirmation message 'Selection saved successfully' appears
✅ Expected Result: All criteria checkboxes can be checked and unchecked correctly, and submitting shows a success confirmation message
Automation Requirements - Selenium with Python
Assertions Needed:
All expected criteria checkboxes are present
Checkboxes can be checked and unchecked
Confirmation message appears after submission
Best Practices:
Use explicit waits to wait for elements
Use descriptive locators (By.ID or By.NAME)
Use Page Object Model to separate page structure from test logic
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 ToolSelectionPage:
    def __init__(self, driver):
        self.driver = driver
        self.criteria_checkboxes = {
            'Cost': (By.ID, 'criteria-cost'),
            'Ease of Use': (By.ID, 'criteria-ease'),
            'Integration': (By.ID, 'criteria-integration'),
            'Support': (By.ID, 'criteria-support'),
            'Features': (By.ID, 'criteria-features')
        }
        self.submit_button = (By.ID, 'submit-btn')
        self.confirmation_message = (By.ID, 'confirmation-msg')

    def wait_for_page(self):
        WebDriverWait(self.driver, 10).until(
            EC.presence_of_element_located(self.submit_button)
        )

    def is_criteria_present(self, name):
        locator = self.criteria_checkboxes.get(name)
        if not locator:
            return False
        try:
            WebDriverWait(self.driver, 5).until(
                EC.presence_of_element_located(locator)
            )
            return True
        except:
            return False

    def set_checkbox(self, name, check=True):
        locator = self.criteria_checkboxes[name]
        checkbox = WebDriverWait(self.driver, 5).until(
            EC.element_to_be_clickable(locator)
        )
        if checkbox.is_selected() != check:
            checkbox.click()

    def click_submit(self):
        btn = WebDriverWait(self.driver, 5).until(
            EC.element_to_be_clickable(self.submit_button)
        )
        btn.click()

    def get_confirmation_text(self):
        msg = WebDriverWait(self.driver, 10).until(
            EC.visibility_of_element_located(self.confirmation_message)
        )
        return msg.text


def test_tool_selection_criteria():
    driver = webdriver.Chrome()
    driver.get('https://example.com/tool-selection')

    page = ToolSelectionPage(driver)
    page.wait_for_page()

    expected_criteria = ['Cost', 'Ease of Use', 'Integration', 'Support', 'Features']

    # Verify all criteria present
    for criterion in expected_criteria:
        assert page.is_criteria_present(criterion), f"{criterion} checkbox not found"

    # Check 'Cost' and 'Ease of Use'
    page.set_checkbox('Cost', True)
    page.set_checkbox('Ease of Use', True)

    # Uncheck 'Cost'
    page.set_checkbox('Cost', False)

    # Submit
    page.click_submit()

    # Verify confirmation message
    confirmation = page.get_confirmation_text()
    assert confirmation == 'Selection saved successfully', "Confirmation message mismatch"

    driver.quit()

This script uses Selenium WebDriver with Python to automate the manual test case.

The ToolSelectionPage class models the page elements using descriptive locators by ID. It includes methods to wait for the page, check presence of criteria checkboxes, set checkbox states, click submit, and get confirmation text.

The test function test_tool_selection_criteria opens the page, verifies all expected criteria checkboxes are present, checks and unchecks checkboxes as per the manual steps, submits the form, and asserts the confirmation message text.

Explicit waits ensure elements are ready before interaction, improving reliability. Using a page object separates page details from test logic, making maintenance easier.

Common Mistakes - 3 Pitfalls
Using hardcoded XPath selectors that are brittle
Not using explicit waits before interacting with elements
Mixing test logic and page structure in the same code
Bonus Challenge

Now add data-driven testing with 3 different sets of criteria selections

Show Hint