Skip to content

Hani/ Testrail exercise #541

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions modules/testrail.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,10 @@ def get_test_case(self, case_id):
"""Get a given Test Case"""
return self.client.send_get(f"get_case/{case_id}")

def get_suites(self, project_id):
"""Get all suites for project"""
return self.client.send_get(f"get_suites/{project_id}")

def update_cases_in_suite(self, suite_id, case_ids, **kwargs):
"""Given a suite and a list of test cases, update all listed
test cases according to keyword args"""
Expand Down
47 changes: 47 additions & 0 deletions modules/testrail_script.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import os
import logging
from modules.testrail_integration import testrail_init

# Configuration
PROJECT_ID = 17
SUITE_NAMES = ["Bookmarks and History", "Drag and Drop", "Find Toolbar"]
AUTOMATION_COVERAGE_VALUE = 3
COMPLETED_STATUS_ID = 4

# Set TestRail credentials
os.environ["TESTRAIL_BASE_URL"] = "https://mozilla.testrail.io"
os.environ["TESTRAIL_USERNAME"] = ""
os.environ["TESTRAIL_API_KEY"] = ""


def get_all_completed_cases(tr, project_id, suite_id):
"""Fetch all completed automated test cases (custom_automation_status = 4)"""
response = tr._get_test_cases(project_id, suite_id)
cases = response.get("cases", [])

# Filter cases that are automated & completed (custom_automation_status == 4)
completed_cases = [case for case in cases if case.get("custom_automated_test_names") and case.get("custom_automation_status") == 4]
logging.info(f"Total cases fetched from suite {suite_id}: {len(completed_cases)}")
return completed_cases


if __name__ == "__main__":
logging.basicConfig(level=logging.INFO)
tr = testrail_init()

# Get suite IDs for the selected suite names
suites = tr.get_suites(PROJECT_ID)
suite_ids = [suite["id"] for suite in suites if suite["name"] in SUITE_NAMES]
logging.info(f"Found suites: {suite_ids}")

all_completed_cases = []
for suite_id in suite_ids:
completed_cases = get_all_completed_cases(tr, PROJECT_ID, suite_id)
all_completed_cases.extend(completed_cases)

logging.info(f"Total completed automated cases found for selected suites: {len(all_completed_cases)}")

for case in all_completed_cases:
tr.update_case_field(case["id"], "custom_automation_coverage", AUTOMATION_COVERAGE_VALUE)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment this out, and insert a line that prints the case ids you would change if it ran live. Post that result here, and if it looks good, I'll give the go-ahead to run the script live. Thanks!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Case IDs to be updated: [127239, 127249, 127271, 2084637, 2084639, 2084641, 2084539, 2084549, 2084489, 2084490, 2084518, 2084524, 2084550, 2084552, 2084553, 2084559, 2084564, 118799, 118800, 118802, 118805, 118806, 118807, 172043, 172045, 216273, 174072, 464474, 936860, 936861, 936864, 937418]

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Total cases fetched from suite 2085: 3
Total cases fetched from suite 2525: 24
Total cases fetched from suite 5259: 5

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That looks right, run the script!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I ran the script successfully. Thanks.


logging.info("All applicable test cases updated successfully!")