Running custom analysis on test results or displaying them along with other data on a personalized dashboard can be useful. You can achieve that by exporting the test results from one or more test runs or plans in a structured json format.
By fetching details about test runs and results, you can use powerful analytical tools to get insights about your testing efforts, or simply display your testing progress in external tools, i.e.:
- Analyze test results in a BI tool
- Display test results on operational dashboards
Getting test runs
You may want to to fetch your test execution data from TestRail to display it or process it in any manner. If you only need an overview of test execution, such as how many tests passed or failed for a set of test runs, you can perform a request similar to the one below.
GET index.php?/api/v2/get_runs/{project_id}
curl -X GET \
-u "user@example.com:password" \
"https://example.testrail.io/index.php?/api/v2/get_runs/27"
{
"offset": 0,
"limit": 250,
"size": 250,
"_links": {
"next": "/api/v2/get_cases/1&limit=250&offset=250",
"prev": null
},
"runs": [
{
"id": 228,
"suite_id": 53,
"name": "New test run",
"description": "Test run description",
"milestone_id": null,
"assignedto_id": 5,
"include_all": false,
"is_completed": false,
"completed_on": 1684939401,
"config": null,
"config_ids": [],
"passed_count": 0,
"blocked_count": 0,
"untested_count": 1,
"retest_count": 0,
"failed_count": 2,
"custom_status1_count": 0,
"custom_status2_count": 0,
"custom_status3_count": 0,
"custom_status4_count": 0,
"custom_status5_count": 0,
"custom_status6_count": 0,
"custom_status7_count": 0,
"project_id": 27,
"plan_id": null,
"created_on": 1684936873,
"updated_on": 1684936873,
"refs": null,
"dataset_id": null,
"created_by": 18,
"url": "https://marketing80testing.testrail-staging.com/index.php?/runs/view/228"
}
]
}
Filtering test runs using query parameters
- All active test runs for project with ID 1 created by user with ID 1 or 2:
GET index.php?/api/v2/get_runs/1&is_completed=0&created_by=1,2
Getting test run results
In case you want to analyze and get insights on results for all your test cases, you can get the results on a per test run basis. This allows you to have more granular control over test results.
GET index.php?/api/v2/get_results_for_run/{run_id}
curl -X GET \
-u "user@example.com:password" \
"https://example.testrail.io/index.php?/api/v2/get_results_for_run/228"
{
"offset": 0,
"limit": 250,
"size": 250,
"_links": {
"next": "/api/v2/get_results/42&limit=250&offset=250",
"prev": null
},
"results": [
{
"assignedto_id": 1,
"comment": "This test passed.",
"created_by": 1,
"created_on": 1393851801,
"custom_step_results": [],
"defects": "TR-1",
"elapsed": "5m",
"id": 801,
"status_id": 1,
"test_id": 91
},
{
"assignedto_id": 1,
"comment": "This test failed: ..",
"created_by": 1,
"created_on": 1393851801,
"custom_step_results": [],
"defects": "TR-1",
"elapsed": "3m",
"id": 802,
"status_id": 5,
"test_id": 92
}
]
}
Filtering test results using query parameters
- The latest 10 results for test run with ID 1 created by user 5
GET index.php?/api/v2/get_results_for_run/1&created_by=5&limit=10