How to get results updated in TestRail from imported features?

I’m using BDD and my scenarios have certain tags including TestRail(123456).

I have code written that reads the results and given the plan or run id, it updates the results into TestRail run.
BUT since there are many new BDD scenarios and features recently added, I want to avoid creating them in TestRail manually, so I want to import the feature file, as this new (?) functionality appeared recently in TestRail.

enter image description here

By doing so, I am unable to find a way to map scenarios from my repo to TestRail.
I was trying to get the id (scenario.getId()) but it’s the run id, not the Scenario id so it won’t work. Has anyone tried that? I’m ran out of ideas

My current code:

Collection<String> tagNames = scenario.getSourceTagNames();
        for (String s : tagNames) {
            if (s.contains("TestRail")) {
                String[] res = s.split("(\\(.*?)");
                caseId = res[1].substring(0, res[1].length() - 1); 
                break;
            }
        }

if (!scenario.isFailed()) {
            data.put("status_id", SUCCESS_STATE);
            data.put("comment", SUCCESS_COMMENT);

        } else {
                data.put("status_id", FAIL_STATE);
                data.put("comment", logError(scenario));
         }        

 client = testRailApiClient();
                client.sendPost("add_result_for_case/" + runId + "/" + caseId, data);

Leave a Comment