Join 34,000+ subscribers and receive articles from our blog about software quality, testing, QA and security.

Issue with implementing add_run for automation. Java(Selenium)



I am new newbie to TestRail/Selenium integration. I just figured out how to add to test cases but now I am having a hard time trying to create new test run through automation. When I create a new test run, the test cases are there but are not ran and the test run name is Master. I want to know how I can rename the new test run to anything in the code and run the test cases. Below is the code.

package trail;

import java.util.HashMap;
import java.util.Map;

import org.json.simple.JSONObject;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;

import testrail.APIClient;
import testrail.APIException;

public class run {

public static String TEST_RUN_ID                = "1";
public static String TESTRAIL_USERNAME          = "xxxxxxxx";
public static String TESTRAIL_PASSWORD          = "xxxxx";
public static String RAILS_ENGINE_URL           = "xxxxxxxx";
public static final int TEST_CASE_PASSED_STATUS = 1;
public static final int TEST_CASE_FAILED_STATUS = 5;
public static WebDriver driver;	

public static void main(String[] args) throws IOException, APIException {
    APIClient client = new APIClient(RAILS_ENGINE_URL);
	// TODO Auto-generated method stub
	System.setProperty("", "/chromedriver");
	driver = new ChromeDriver();
	if(driver.findElement(By.xpath("//*[@id=\"hplogo\"]")).isDisplayed()) {

		addResultForTestCase("1", TEST_CASE_PASSED_STATUS, "");
	} else
		addResultForTestCase("1", TEST_CASE_FAILED_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);

        JSONObject c = (JSONObject) client.sendGet("get_case/1/1");
        Map data = new HashMap();
        data.put("status_id", status);
       data.put("comment", "Test Executed - Status updated automatically from Selenium test automation.");
       client.sendPost("add_run/"+testRunId+"/"+testCaseId+"",data );
       client.sendPost("add_result_for_case/"+testRunId+"/"+testCaseId+"",data );


First and foremost - please edit your post and remove the credentials… everyone can use them, you know ?

Second - do not use your password when accessing the api, generate an API Token (

Regarding the add_run: take a look at - Request fields tell you how you can pass what parameters to the method. Like name in your case to set the name of the run.

In general - the api is well documented and quite helpful:


So I figured out how to use add a run. I was having a hard time understanding the PHP lingo so it was a little trial and error.

Create an object:
JSONObject object = (JSONObject) APIclient.sendGet(“get_case/1/1”);

Create a hash that holds the test data:
Map data = new HashMap();

Add to the data:
data.put(“status_id”, 1);
data.put(“name”, “new name of run”);

Send Post using the add_run call:
client.sendPost(“add_run/”+testRunId+"/"+testCaseId+"",data );

The issue I am having now is adding the data to the new test case. Since the new test cases have new IDs they will not be added. Is there a way I could point the data to the new IDs?

Also thanks for the password API tip bygones.