Tool selection criteria in Testing Fundamentals - Build an Automation Script
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.
Now add data-driven testing with 3 different sets of criteria selections