javaseleniumtestingautomated-teststestrail

Create a test run in java using testrail api


I am using java to update test cases in testrail. But I am having an issue with the test run ids. I don't want to update every time I create a new run, I'd like to create a run on java and use the id for every test case. Is there a way this is possible ? Also how do I go to different section etc within testrail ? . Here is the code I use to update the test cases.

public class close_how_to_play extends ConditionsWebDriverFactory{

public static String TEST_RUN_ID                = "1741";
public static String TESTRAIL_USERNAME          = "testgame@game.com";
public static String TESTRAIL_PASSWORD          = "Password1";
public static String RAILS_ENGINE_URL           = "https://testgame.testrail.com/";
public static final int TEST_CASE_PASSED_STATUS = 1;
public static final int TEST_CASE_FAILED_STATUS = 5;



@org.testng.annotations.Test
public void how_to_play() throws IOException, APIException {

    Header header = new Header();
    header.select_how_to_play();
    HowToPlay howtoplay = new HowToPlay();
    howtoplay.got_how_to_play();
    addResultForTestCase("17107",TEST_CASE_PASSED_STATUS," ");


}
public static void addResultForTestCase(String testCaseId, int status,
                                        String error) throws IOException, APIException {

    String testRunId = TEST_RUN_ID;
    APIClient client = new APIClient(RAILS_ENGINE_URL);
    client.setUser(TESTRAIL_USERNAME);
    client.setPassword(TESTRAIL_PASSWORD);
    Map data = new HashMap();
    data.put("status_id", status);
    data.put("comment", "Test Executed - Status updated automatically from Selenium test automation.");
    client.sendPost("add_result_for_case/"+testRunId+"/"+testCaseId+"",data );

}

Solution

  • Testrun is to be created every time. And You have to create it every time, so You know what You've tested.

    So Your algorithm should be:

    1. Create Testrun (get some id TR123) - assign testcases to testrun (all or just few, nevermind) enter image description here

    2. add testresults to each test-case, enter image description here

    Hope this helps,