Title: How to send my test results from selenium to testrail
Tags: java;selenium;testrail
Question: 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          = "sbush@example.com";
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;
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.
Comment: Possible duplicate of [Integrate Selenium test results with TestRail 4.0](https://stackoverflow.com/questions/31344490/integrate-selenium-test-results-with-testrail-4-0)

Comment: I checked with the docs, there doesn't look a problem with  your code.The error may be actually what it looks like, are you sure you can login with the given credentials in the URL? (I cannot access the URL, https://testproj.testrail.com/, is it a private server or something?)

Comment: The URL format also doesn't look bad to me. Can you try the another format though, "http:///testrail/"? Yeah, you don't have to share your credentials but you are able to login with them manually right?

Comment: Oh no sorry I just changed my url for putting it up on the site, I didn’t want my login available. Would I be missing anything else I wonder. Or is he the url format incorrect. I’m not sure

Comment: Yea im able to Login from there manually

Here is the accepted answer: 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&gt;/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:
And than test case ID is different from testrun id.


{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 1, 'CommentCount': 5, 'ContentLicense': 'CC BY-SA 4.0', 'CreationDate': '2018:00:07/06/18', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<java><selenium><testrail>', 'Title': 'How to send my test results from selenium to testrail', 'ViewCount': 1768, 'id': 51209944, 'user_AboutMe': None, 'user_AccountId': 13423518.0, 'user_DisplayName': 'fearghal O reilly', 'user_Reputation': 143.0, 'user_Views': 41.0, 'user_id': 9685588.0}}