Why defect tracking improves quality in Testing Fundamentals - Automation Benefits in Action
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 DefectTrackingPage: def __init__(self, driver): self.driver = driver self.wait = WebDriverWait(driver, 10) def login(self, username, password): self.driver.get('https://defecttracker.example.com/login') self.wait.until(EC.visibility_of_element_located((By.ID, 'username'))).send_keys(username) self.driver.find_element(By.ID, 'password').send_keys(password) self.driver.find_element(By.ID, 'loginBtn').click() self.wait.until(EC.url_contains('/dashboard')) def open_defect(self, defect_id): self.wait.until(EC.visibility_of_element_located((By.ID, 'searchBox'))).send_keys(defect_id) self.driver.find_element(By.ID, 'searchBtn').click() self.wait.until(EC.visibility_of_element_located((By.CSS_SELECTOR, f'div.defect-item[data-id="{defect_id}"]'))).click() def get_defect_details(self): details = self.wait.until(EC.visibility_of_element_located((By.ID, 'defectDetails'))) return details.text def update_status(self, new_status, comment): status_dropdown = self.wait.until(EC.element_to_be_clickable((By.ID, 'statusDropdown'))) status_dropdown.click() option = self.wait.until(EC.element_to_be_clickable((By.XPATH, f"//option[text()='{new_status}']"))) option.click() comment_box = self.driver.find_element(By.ID, 'commentBox') comment_box.clear() comment_box.send_keys(comment) self.driver.find_element(By.ID, 'updateBtn').click() self.wait.until(EC.text_to_be_present_in_element((By.ID, 'currentStatus'), new_status)) def get_current_status(self): status = self.wait.until(EC.visibility_of_element_located((By.ID, 'currentStatus'))) return status.text def verify_defect_in_list(self, status_list_id, defect_id): self.driver.find_element(By.ID, status_list_id).click() self.wait.until(EC.visibility_of_element_located((By.CSS_SELECTOR, f'div.defect-item[data-id="{defect_id}"]'))) def test_defect_tracking(): driver = webdriver.Chrome() page = DefectTrackingPage(driver) try: page.login('tester@example.com', 'TestPass123') defect_id = 'DEF-101' page.open_defect(defect_id) details = page.get_defect_details() assert 'Steps to reproduce' in details, 'Defect details missing steps to reproduce' page.update_status('In Progress', 'Started working on defect') status = page.get_current_status() assert status == 'In Progress', 'Status did not update to In Progress' page.update_status('Resolved', 'Fixed the defect') status = page.get_current_status() assert status == 'Resolved', 'Status did not update to Resolved' page.verify_defect_in_list('resolvedDefectsTab', defect_id) finally: driver.quit() if __name__ == '__main__': test_defect_tracking()
This script uses Selenium WebDriver with Python to automate defect tracking verification.
The DefectTrackingPage class follows the Page Object Model to keep page actions organized.
We use explicit waits to wait for elements to load before interacting, avoiding timing issues.
The test logs in, opens a defect by ID, checks defect details, updates status twice, and verifies the status changes correctly.
Assertions confirm that defect details contain expected text and that status updates reflect properly.
Finally, it verifies the defect appears in the resolved defects list after status update.
This approach ensures the defect tracking tool works as expected, which helps improve software quality by managing defects effectively.
Now add data-driven testing with 3 different defect IDs and statuses to update