Create and verify a new test case in TestRail
Preconditions (3)
✅ Expected Result: The new test case titled 'Verify login functionality' is created and visible in the test case list
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.
Now add data-driven testing with 3 different test case titles and descriptions
Jira and TestRail?Pass the test and this pattern moves unknown