fearghal O reilly
fearghal O reilly

Reputation: 140

How to send my test results from selenium to testrail

I am having trouble sending my test results from selenium to testrail. I cant seem to figure it out using the paperwork provided. I am currently using this:

public class login_errors extends ConditionsWebDriverFactory {

public static String TEST_RUN_ID                = "R1713";
public static String TESTRAIL_USERNAME          = "[email protected]";
public static String TESTRAIL_PASSWORD          = "Password1";
public static String RAILS_ENGINE_URL           = "https://testproj.testrail.com/";
public static final int TEST_CASE_PASSED_STATUS = 1;
public static final int TEST_CASE_FAILED_STATUS = 5;


@Test
public void login_errors() throws IOException, APIException {
    Header header = new Header();
    header.guest_select_login();
    Pages.Login login = new Pages.Login();
    login.login_with_empty_fields();
    login.login_with_invalid_email();
    login.email_or_password_incorrect();
    login.login_open_and_close();
    login_errors.addResultForTestCase(TEST_RUN_ID,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 );

}

}

But i keep getting the following exception:

com.gurock.testrail.APIException: TestRail API returned HTTP 401("Authentication failed: invalid or missing user/password or session cookie.")

Can anybody help me on the exact way this should be done out in java? I am not sure I am doing it correctly.

Upvotes: 1

Views: 2355

Answers (1)

Kovacic
Kovacic

Reputation: 1481

I'm using my own custom made API for testrail, but it is all based on same thing.

But looking to official gurrock, documentation

First You need to add "testrail/" at the end of Your URL endpoint,

APIClient client = new APIClient("http://<server>/testrail/");
client.setUser("..");
client.setPassword("..");

Should be like this:

public static String RAILS_ENGINE_URL ="https://testproj.testrail.com/testrail/";

Second thing what I found out is that You're sending test run id in variable for testcase ID, this is not same.

And another thing is that test case ID shouldn't be with anything in front just pure number, not like "R123" but "123"

And Your method should than accept one more parameter, testRunId

public static void addResultForTestCase(String testRunId, 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 );
}

And another thing is that You have to have created testrun, so You can have Yourself your testrun ID, like pic bellow:

enter image description here

And than test case ID is different from testrun id.

Upvotes: 1

Related Questions