Skip to content

Commit 7d7973b

Browse files
Hani YacoubHani Yacoub
authored andcommitted
Testrail set all custom sub teste suites to functional
1 parent 48f5c8d commit 7d7973b

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

modules/testrail.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,10 @@ def get_test_case(self, case_id):
160160
"""Get a given Test Case"""
161161
return self.client.send_get(f"get_case/{case_id}")
162162

163+
def get_suites(self, project_id):
164+
"""Get all suites for project"""
165+
return self.client.send_get(f"get_suites/{project_id}")
166+
163167
def update_cases_in_suite(self, suite_id, case_ids, **kwargs):
164168
"""Given a suite and a list of test cases, update all listed
165169
test cases according to keyword args"""
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import os
2+
import logging
3+
from modules.testrail_integration import testrail_init
4+
5+
# Configuration
6+
PROJECT_ID = 17
7+
# SUITE_NAMES = ["Bookmarks and History", "Drag and Drop", "Find Toolbar", "Audio/Video", "Downloads", "WebRTC"]
8+
CUSTOM_SUB_TEST_SUITES = 1 # "Functional Only"
9+
10+
# Set TestRail credentials
11+
os.environ["TESTRAIL_BASE_URL"] = "https://mozilla.testrail.io"
12+
os.environ["TESTRAIL_USERNAME"] = ""
13+
os.environ["TESTRAIL_API_KEY"] = ""
14+
15+
16+
def get_all_cases_from_suite(tr, project_id, suite_id):
17+
"""Fetch all test cases in the suite"""
18+
response = tr._get_test_cases(project_id, suite_id)
19+
cases = response.get("cases", [])
20+
logging.info(f"Total cases fetched from suite {suite_id}: {len(cases)}")
21+
return cases
22+
23+
24+
if __name__ == "__main__":
25+
logging.basicConfig(level=logging.INFO)
26+
tr = testrail_init()
27+
28+
# Get suite IDs for the selected suite names
29+
suites = tr.get_suites(PROJECT_ID)
30+
suite_ids = [suite["id"] for suite in suites]
31+
logging.info(f"Found suites: {suite_ids}")
32+
33+
all_cases = []
34+
for suite_id in suite_ids:
35+
cases = get_all_cases_from_suite(tr, PROJECT_ID, suite_id)
36+
all_cases.extend(cases)
37+
38+
logging.info(f"Total test cases found for selected suites: {len(all_cases)}")
39+
40+
for case in all_cases:
41+
tr.update_case_field(case["id"], "custom_sub_tests_suites", CUSTOM_SUB_TEST_SUITES)
42+
43+
logging.info("All applicable test cases updated to 'Functional Only' successfully!")

0 commit comments

Comments
 (0)