0
0
Testing Fundamentalstesting~15 mins

Test management tools (Jira, TestRail) in Testing Fundamentals - Build an Automation Script

Choose your learning style9 modes available
Create and verify a new test case in TestRail
Preconditions (3)
Step 1: Navigate to the TestRail project dashboard
Step 2: Click on the 'Test Cases' tab
Step 3: Click the 'Add Test Case' button
Step 4: Enter 'Verify login functionality' in the Title field
Step 5: Enter 'Test the login page with valid credentials' in the Description field
Step 6: Select the appropriate section for the test case
Step 7: Click the 'Add Test Case' button to save
Step 8: Verify that the new test case appears in the test case list with the correct title
✅ Expected Result: The new test case titled 'Verify login functionality' is created and visible in the test case list
Automation Requirements - Selenium with Python
Assertions Needed:
Verify the test case title input field accepts the correct text
Verify the test case description input field accepts the correct text
Verify the new test case appears in the test case list after saving
Best Practices:
Use explicit waits to handle dynamic page elements
Use Page Object Model to separate page interactions
Use meaningful locators like IDs or stable CSS selectors
Include clear assertion messages for test failures
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 TestRailPage:
    def __init__(self, driver):
        self.driver = driver
        self.wait = WebDriverWait(driver, 10)

    def go_to_project_dashboard(self):
        self.driver.get('https://yourtestrailurl.com/index.php?/projects/overview/1')

    def click_test_cases_tab(self):
        tab = self.wait.until(EC.element_to_be_clickable((By.ID, 'navigation-test-cases')))
        tab.click()

    def click_add_test_case(self):
        add_button = self.wait.until(EC.element_to_be_clickable((By.ID, 'add_case_button')))
        add_button.click()

    def enter_title(self, title):
        title_field = self.wait.until(EC.visibility_of_element_located((By.ID, 'title')))
        title_field.clear()
        title_field.send_keys(title)

    def enter_description(self, description):
        desc_field = self.driver.find_element(By.ID, 'custom_description')
        desc_field.clear()
        desc_field.send_keys(description)

    def select_section(self):
        # Assuming default section is selected or no action needed
        pass

    def save_test_case(self):
        save_button = self.driver.find_element(By.ID, 'accept')
        save_button.click()

    def verify_test_case_in_list(self, title):
        # Wait for the test case list to refresh and check for title
        self.wait.until(EC.visibility_of_element_located((By.CSS_SELECTOR, 'table.cases')))
        cases = self.driver.find_elements(By.CSS_SELECTOR, 'table.cases tbody tr td.title')
        titles = [case.text for case in cases]
        assert title in titles, f"Test case titled '{title}' not found in the list"


def test_create_test_case():
    driver = webdriver.Chrome()
    driver.implicitly_wait(5)
    try:
        page = TestRailPage(driver)
        page.go_to_project_dashboard()
        page.click_test_cases_tab()
        page.click_add_test_case()
        test_title = 'Verify login functionality'
        test_description = 'Test the login page with valid credentials'
        page.enter_title(test_title)
        page.enter_description(test_description)
        page.select_section()
        page.save_test_case()
        page.verify_test_case_in_list(test_title)
    finally:
        driver.quit()

if __name__ == '__main__':
    test_create_test_case()

This script uses Selenium with Python to automate creating a test case in TestRail.

We use a Page Object Model class TestRailPage to organize page actions like navigating, clicking buttons, and entering text.

Explicit waits ensure elements are ready before interacting, avoiding timing issues.

Assertions check that the test case title appears in the list after saving, confirming success.

Finally, the test function runs the steps and closes the browser.

Common Mistakes - 3 Pitfalls
Using hardcoded sleeps instead of explicit waits
Using brittle XPath selectors that break easily
Not verifying that inputs accept the correct text before saving
Bonus Challenge

Now add data-driven testing with 3 different test case titles and descriptions

Show Hint