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

Integration TestRail and SeleniumWebDriver

Hi, any help me please!

What link has TestCases with TestRun? I want to link them to immediately add the test status to TestRun

Regards, Oleg

HI Oleg,

Thanks for the post! Test Runs in TestRail are based on the test cases in your project.

Each test case in your project has it’s own ID. In TestRail’s UI, these case IDs begin with C, such as C123. When using TestRail’s API for integrating with tools like Selenium, you would only need the digits, as the ‘C’ is only used to help identify the item you are viewing inside TestRail. Other entities in TestRail’s UI will be prefixed with a letter corresponding to the entity, such as ‘R’ for run or plan, ‘T’ for test, etc.

When you create a test run using your test cases, TestRail creates a set of tests based on the cases you chose for the run. These tests will have their own unique IDs separate from their associated test cases in the project.

When you submit results to a test run, you can either use the ‘add_results’ API endpoint along with the test IDs, or the ‘add_results_for_cases’ API endpoint along with the case IDs. You can also find examples of these API endpoints on our website here.

Hope this helps,
Jon

Hi Jon,
I get next error Exception in thread “main” APIException: TestRail API returned HTTP 400(“Field :results is a required field.”)
at APIClient.sendRequest(APIClient.java:292)
at APIClient.sendPost(APIClient.java:129)
at Main.main(Main.java:56)

Part of my code:
JSONObject c = (JSONObject) client.sendGet(“get_case/31”);

    System.out.println(c.get("title"));
    Map data = new HashMap();
    /*data.put("test_id", 67);
    data.put("status_id", new Integer(5));
    data.put("comment", "This test worked fine!");*/
    ArrayList list = new ArrayList();
    list.add(31);
    list.add(33);
  /*  data.put("name", "Test1");
    data.put("include_all", false);
    data.put("case_ids", list);*/

    //client.sendPost("add_run/3", data);
    data.put("test_id", list);
    data.put("status_id", new Integer(2));
    data.put("comment", "This test worked fine!");
    client.sendPost("add_results_for_cases/31/31", data); //56 line

I’m thinking error in depends with different IDs case(project IDs and Run IDs). I want using IDs directly for recording the results(statuses) together with Test Run. Currently me need to look IDs case in Test Run before execution Test Results(add_results)

Hi @Oleg86,

The error (“Field :results is a required field.”) indicates your array is not formatted properly. When using the add_results_for_cases method, TestRail’s API expects an array of results for tests, formatted as follows:

 {
	"results": [
		{
			"test_id": 101,
			"status_id": 5,
			"comment": "This test failed",
			"defects": "TR-7"

		},
		{
			"test_id": 102,
			"status_id": 1,
			"comment": "This test passed",
			"elapsed": "5m",
			"version": "1.0 RC1"
		},

		..

		{
			"test_id": 101,
			"assignedto_id": 5,
			"comment": "Assigned this test to Joe"
		}

		..
	]
}

Based on the details you provided, you do not appear to be building your array properly, as each item in the array should contain a set of results for a test case in your run. You can find additional details on this in our documentation here.

Hope this helps,
Jon

That’s right. But how do I add status_id immediately when running Test Run? Currently I first run Test_Run then go to the Test_Run to see IDs of it and IDs of cases for add_results and status_id for previous cases.