gurock / trcli

TR CLI (trcli) is a command line tool for interacting with TestRail.
Mozilla Public License 2.0
47 stars 42 forks source link

Add possibility to link one automated test to multiple test cases by name or property #133

Closed ssv-w32 closed 1 year ago

ssv-w32 commented 1 year ago

What would you like the TestRail CLI to be able to do?

I'd like to be able to add multiple test cases in run result like this:

--case-matcher "property"

        <testcase classname="tests.whatever"
                  name="test_create_whatever"
                  time="31.917">
            <properties>
                <property name="test_id" value="C1"/>
                <property name="test_id" value="C2"/>
                <property name="test_id" value="C3"/>
            </properties>
        </testcase>

OR

--case-matcher "name"

        <testcase classname="tests.whatever"
                  name="C1_C2_C3_test_create_whatever" time="31.917" >
        </testcase>

Why is this feature necessary on the TestRail CLI?

I want it because I have automated tests that cover >1 test case from TestRail as part of one test.

More details

No response

Interested in implementing it yourself?

No

ssv-w32 commented 1 year ago

this could be possible solution for properties

diff --git a/trcli/readers/junit_xml.py b/trcli/readers/junit_xml.py
index 4475193..4572695 100644
--- a/trcli/readers/junit_xml.py
+++ b/trcli/readers/junit_xml.py
@@ -77,7 +77,7 @@ class JunitParser(FileParser):
                         processed_section_properties.append(prop.name)
                 for case in section:
                     cases_count += 1
-                    case_id = None
+                    multiple_ids = []
                     case_name = case.name
                     attachments = []
                     result_fields = []
@@ -90,7 +90,7 @@ class JunitParser(FileParser):
                     for case_props in case.iterchildren(Properties):
                         for prop in case_props.iterchildren(Property):
                             if prop.name and self.case_matcher == MatchersParser.PROPERTY and prop.name == "test_id":
-                                case_id = int(prop.value.lower().replace("c", ""))
+                                multiple_ids.append(int(prop.value.lower().replace("c", "")))
                             if prop.name and prop.name.startswith("testrail_attachment"):
                                 attachments.append(prop.value)
                             if prop.name and prop.name.startswith("testrail_result_field"):
@@ -109,27 +109,28 @@ class JunitParser(FileParser):
                     if error:
                         self.env.elog(error)
                         raise Exception(error)
-                    result = TestRailResult(
-                        case_id,
-                        elapsed=case.time,
-                        junit_result_unparsed=case.result,
-                        attachments=attachments,
-                        result_fields=result_fields_dict
-                    )
-                    for comment in reversed(comments):
-                        result.prepend_comment(comment)
-                    if sauce_session:
-                        result.prepend_comment(f"SauceLabs session: {sauce_session}")
-                    test_cases.append(
-                        TestRailCase(
-                            section.id,
-                            case_name,
-                            case_id,
-                            result=result,
-                            custom_automation_id=automation_id,
-                            case_fields=case_fields_dict
+                    for single_id in multiple_ids:
+                        result = TestRailResult(
+                            single_id,
+                            elapsed=case.time,
+                            junit_result_unparsed=case.result,
+                            attachments=attachments,
+                            result_fields=result_fields_dict
+                        )
+                        for comment in reversed(comments):
+                            result.prepend_comment(comment)
+                        if sauce_session:
+                            result.prepend_comment(f"SauceLabs session: {sauce_session}")
+                        test_cases.append(
+                            TestRailCase(
+                                section.id,
+                                case_name,
+                                single_id,
+                                result=result,
+                                custom_automation_id=automation_id,
+                                case_fields=case_fields_dict
+                            )
                         )
-                    )
                 test_sections.append(
                     TestRailSection(
                         section.name,
mnataraj17 commented 1 year ago

It's a Duplicate of https://github.com/gurock/trcli/issues/130 It would be great if someone could consider this. Lot of organizations follow this pattern of having multiple testrail cases in one Automated test in order to make tests more efficient. Thanks!

d-rede commented 1 year ago

Thanks for your feedback. I'm closing this issue since it's a duplicate, but we will follow-up on https://github.com/gurock/trcli/issues/130.