0
0
Testing Fundamentalstesting~15 mins

Why defect tracking improves quality in Testing Fundamentals - Automation Benefits in Action

Choose your learning style9 modes available
Verify defect tracking improves software quality
Preconditions (2)
Step 1: Open the defect tracking tool and log in
Step 2: Navigate to the project dashboard
Step 3: Review the list of open defects
Step 4: Select a defect and verify it has detailed information (steps to reproduce, severity, status)
Step 5: Update the defect status to 'In Progress' and add a comment
Step 6: Verify that the defect status updates correctly
Step 7: After fixing, change the defect status to 'Resolved' and verify it appears in resolved defects list
Step 8: Check the defect report summary to see defect trends over time
✅ Expected Result: Defects are properly logged, updated, and tracked. Status changes reflect accurately. Defect trends show improvement in quality over time.
Automation Requirements - Selenium with Python
Assertions Needed:
Verify defect details are displayed correctly
Verify defect status updates correctly after changes
Verify defect appears in correct defect list after status change
Best Practices:
Use explicit waits to handle page loading
Use Page Object Model to separate page interactions
Use clear and maintainable locators (id, name, or CSS selectors)
Include assertions after each critical step
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 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.

Common Mistakes - 4 Pitfalls
Using hardcoded sleeps instead of explicit waits
Using brittle XPath locators that rely on full paths
Not verifying the defect status after update
Mixing page actions and assertions in test code without separation
Bonus Challenge

Now add data-driven testing with 3 different defect IDs and statuses to update

Show Hint