Automation suite and TestRail API

Hello!

I have a test automation suite that has been based off test cases in TestRail. The test case will have an ID of say R434 which matches the test case ID in TestRail.

My idea is that when the test case is run it automatically marks the corresponding TestRail case with pass or fail. I know TestRail has an API but I don’t know where to start in getting them to link up.

Can anyone give me some pointers for where to look for the answer? Any articles or similar?

Thanks :slightly_smiling_face:

I’d start with the TestRail API site. The index includes listings with examples of accessing the API.

I’d start with a dummy test case in TestRail to mess with if you can do that. Use that to create the calls you want, then wrap the calls you’re looking for so that you can do something like the pseudo-code below:

// run the test case 
// assert something
string Status = MyAssertion.result;
UpdateTestCase("R434", Status);

Then your API code would have a call to POST index.php?/api/v2/add_result/:test_id and you’d use your data in the call.

You should also check exactly what you’re referring to, since according to the API a test case is not the same as a test, so there might be additional lookups involved.

Exactly how you’d code the connection would depend on what language you’re using as well as how you’re breaking up your tests and test cases. The API docs have detailed instructions for access via Java, PHP, Python, Ruby, and Dot Net (C# or VB.NET)

1 Like

Thank you! :star2:

I will do some tinkering… I am not too familiar with APIs so this is a massive help.

Hi,

We are using TestRail at GIS as well!
How do you find it? Is it very user friendly in you opinion?

I have created a Python script that takes two parameters:

  • SuiteName - it’s a String
  • TestCaseIDs - list of Test Cases IDs (in your case it’s test name)

Then in test script I can use methods like:
AddResult(“TestCaseID”, “PASSED”)
or when test has failed:
AddResult(“TestCaseID”, “FAILED”, “Error message that will be added to testcase in TestRail”)

From my TestRail experience, you can’t mark test with results when it is not in Test Run, so my script does:

  1. Creates a test run in TestRail based on provided SuiteName and TestCaseIDs.
  2. Mark tests in that run according to assertion result.
  3. Close test run in TestRail.

If you need more details, please let me know.

Regards,
Maciej

1 Like