1

I am migrating to maven and Now it has dependency

<!-- https://mvnrepository.com/artifact/com.codepine.api/testrail-api-java-client -->
    <dependency>
      <groupId>com.codepine.api</groupId>
      <artifactId>testrail-api-java-client</artifactId>
      <version>2.0.1</version>
    </dependency>

I have written the below code to update the result..

TestRail testrail= TestRail.builder("https://mytestrail.domain.com", "username", "password").applicationName("appname").build();
Tests tests = testrail.tests();
java.util.List<com.codepine.api.testrail.model.Test> lst = tests.list(43662).execute();
System.out.println(lst.get(0));
System.out.println(lst.size());
List<ResultField> customResultFields = testrail.resultFields().list().execute();
//HashMap data = new HashMap();
//data.put("comment", "Test Purpose for all");
//customResultFields= (java.util.List<ResultField>) data;
int status=5;
testrail.results().addForCase(43662, 30056283, new Result().setStatusId(status), customResultFields).execute();

I have a list of step details which is extracted from ExtentReport. So basically how to update my own custom message instead of just "This test was marked as 'Failed' or 'Passed'"

By seeing this.. https://www.gurock.com/testrail/docs/user-guide/howto/fields

May be we need to create something on the Field class. But anybody has idea on that would be good to guide that complete that. As I am using automation results.. i dont want each step result.. Just adding as comment entire log and make it pass/fail.

ChanGan
  • 4,254
  • 11
  • 74
  • 135

3 Answers3

0

Result has few more options to add like setComment along with Status..

testrail.results().addForCase(43662, 30056283, new Result().setComment("Test Purpose Print as Pass").setStatusId(status), customResultFields).execute();

It will set the comment whatever you are giving and change the status..

ChanGan
  • 4,254
  • 11
  • 74
  • 135
0

You can define a Mapper named Data and put the necessary information in it. You can then add this data as a parameter to the http request.

public static void sendScenarioResults(boolean failed, int runId, int caseId, String errorMessage) {
        try {
            Map data = new HashMap();
            data.put("status_id", failed ? 5 : 1);
            data.put("comment", errorMessage);
            client.sendPost("add_result_for_case/" + runID + "/" + caseId, 
            data);
        } catch (IOException e) {
            e.printStackTrace();
        } catch (APIException e) {
            e.printStackTrace();
        }
    }

}

In addition, you can add a lot of information to the data, you can use Testrail Api docs for this.

Testrail Api docs

Mert Ekinci
  • 352
  • 2
  • 13
-1

Based on your testing framework (JUnit of TestNG), try to use one of these libs:

Both of them have Medium articles on how to integrate it just in a few steps (see README.md there)

Villa_7
  • 508
  • 4
  • 14