Search code examples
javatestrail

How to add my comment in Test Result in the TestRail using testrail-api-java-client


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.


Solution

  • 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..