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

Run ID tracking in Automated Test


Hello Team,

I am able to Integrate Test Rail Api with Test NG and Selenium Webdriver. Now the only doubt I have is like how to track Test Run ID. Is this the only way to track that if I am not Executing the Script from TestRail UI.

1.Go to Test Rail and Create a Test Run.
2.Take the Test Run Id from UI.
3.Give that Test Run Id to My Automation Run(Example: In Some Config File)
4.Track the same Test Run Id and use that with the TestCase ID.

Please suggest If any possible solution for this Problem.


Hi Pawan,

Thanks for your posting. Most integrations create a new test run/plan as part of the automated tests and then add test results to the new run/plan. An alternative is to reuse the same run/plan over a longer period (e.g. for the entire sprint) and you can then create the run/plan in TestRail and add the ID to a configuration file or to your code as you suggested as well.



Hello Tobias,

Thanks for your Reply, I am able to integrate Webdriver/TestNG and TestRail.

I am trying to describe what I did so far and I think this will help other people and I can get feedbacks from Other People about the Implementation.

STEP 1: First Create One new Annotation class

    public @interface UseAsTestRailId
        int testRailId() default 0;
        String[] tags() default "";

STEP 2: Use the above annotation in TestNg Class File with Other Test.
**** Every @Test here is mapped with the Use case In Test Rail So we got the TestRail Unique Id for every Test.****

@UseAsTestRailId(testRailId=<TestRail Id for this Usecase>)
public void yourTestNumberSomething()
  // Do your testing Steps here which are mapped with testRail Case.

STEP 3: You can Use TestNG Listner for Every Test Class, So that you can execute the Test Rail API after the test Execution.

public class TestIngClass {
    // All the Test Will be here ...

STEP 4: You need to Call the test Rail API’s from Listener Class. Like I am Calling the API in the on Test Success Method.

public void onTestSuccess(ITestResult result) {
String TestID=null;
IClass obj = result.getTestClass();
Class newobj = obj.getRealClass();
Method testMethod = newobj.getMethod(result.getName());
if (testMethod.isAnnotationPresent(UseAsTestRailId.class)) 
UseAsTestRailId useAsTestName = testMethod.getAnnotation(UseAsTestRailId.class);
// Get the TestCase ID for Test Rail
TestID = Integer.toString(useAsTestName.testRailId());
System.out.println("Test Rail ID = " + TestID);

// Now You can call the Test Rail Post API call to update the Result in Test Rail Based on the Test Run Id and TestCase ID.

JSONObject r = (JSONObject) client.sendPost("add_result_for_case/TestCaseID/TestRunID", data);

and Its Done …

You can change and twist the code and Logic based on your requirements but i think this might help people in getting started with Integration.

Pawan Garia


Thanks for sharing this, Pawan!



Hi @pawangaria

how did you get TestRunID?


Hi there,

Thank you for your post. You can get the run ID of a test run by using the get_runs method:

You can also use the run ID by using the get_plans method as well if your test run sits inside of a test plan:


thank for your help @martylavender


No problem. I am glad I was able to help.


Hi all,
I’m working with TestNg + Allure. I integrated tests like you described above using @TmsLink("") allure annotation but I have one problem. How can I integrate it using Data-driven Test?
Could someone help?