Importing test results

Centralizing test results in TestRail is a very compelling use case. It helps you consolidate all your testing efforts in one place, allowing you to have more visibility and control over testing, as well as enabling you to generate any of the rich test reports provided by TestRail.

With the ability to programmatically create test runs and import results, you can implement integrations such as:

  • Create runs and upload test results from test automation suites
  • Updating test runs with outsourced test results

Real examples Use case
TestRail CLI Test run creation and results upload from test automation reports
Functionize Test run creation and results upload from automated tests
Katalon Test run creation and results upload from automated tests
Global App Testing Submits results added by external testers

Creating a test run

Test runs work as containers for the tests you want to execute, so you can submit your results. To add a simple test run, you can use the following endpoint.

Request Request Body Example Response Body Example

POST index.php?/api/v2/add_run/{project_id}

curl -X POST \ 
  -u "user@example.com:password" \ 
  -F "@path/to/data.json" \ 
  "https://example.testrail.io/index.php?/api/v2/add_run/12"

Adding results to a test run using case IDs

To add results to a test run, you can make use of case IDs to map each result against the respective test case. Besides actual results, you can also add a simple comment, as you can see in the example body content. To add your results, you can use the following endpoint.

 

If you configured custom result fields, you can also submit values using the pattern custom_field_name, such as custom_failure_severity in the example below.

 

You can find the status ids and their details by executing the following request:
GET index.php?/api/v2/get_statuses

The default statuses are:
1 - Passed
2 - Blocked
3 - Untested (default value, can’t be used to submit a new status)
4 - Retest
5 - Failed

Request Request Body Example Response Body Example

POST index.php?/api/v2/add_results_for_cases/{run_id}

curl -X POST \ 
  -u "user@example.com:password" \ 
  -F "@path/to/data.json" \ 
  "https://example.testrail.io/index.php?/api/v2/add_results_for_cases/228"

Adding results with separated test steps

Separated test steps are a powerful mechanism supported by TestRail to have a more granular control of your test results. Besides setting a general test result, you can also set the a result for each step, and in case the step failed, you can submit the actual behavior. You can submit step results using a body content similar to the one below.

Request Request Body Example Response Body Example

POST index.php?/api/v2/add_results_for_cases/{run_id}

curl -X POST \ 
  -u "user@example.com:password" \ 
  -F "@path/to/data.json" \ 
  "https://example.testrail.io/index.php?/api/v2/add_results_for_cases/228"

Importing attachments

Attachments are very useful to provide additional context for your test results, specially when tests fail. You can add any type of attachment, such as screenshots, videos, execution logs, among others.

 

Note that the maximum allowed upload size is set to 256MB.

Request Request Body Example Response Body Example

POST index.php?/api/v2/add_attachment_to_result/{result_id}
Content-Type: multipart/form-data

curl -X POST \ 
  -u "user@example.com:password" \ 
  -H "Content-Type: multipart/form-data" \
  -F "attachment=@C:\\image.jpg" \ 
  "https://example.testrail.io/index.php?/api/v2/add_attachment_to_result/8661"

Closing a test run

In case you don’t want your imported test runs and results to be modified by anyone, you can also close them by using the following endpoint.

Request Request Body Example Response Body Example

POST index.php?/api/v2/close_run/{run_id}

curl -X POST \ 
  -u "user@example.com:password" \ 
  -H "Content-Type: application/json" \
  "https://example.testrail.io/index.php?/api/v2/close_run/228"

 

Was this article helpful?
3 out of 15 found this helpful