Rest API - Tests
Some of the endpoints use URL parameters. Make sure you are familiar with how to use it with Postman. For more information see Use REST APIs Using Postman.
The Reporter provides you with a Rest API that gives you direct access to the test data and statistics.
Concepts
- Key - Key and value construct a tag. Each test has a subset of available tags with various values that describe the test specifics. Example: date.
- Project - Concept derived from the cloud. Each project has its own resources (users, devices) and can be used to create a separation of testing efforts.
- Test - Single test execution instance.
Get Test By ID
Test with a specified id of the currently selected project.
This API is available for all user roles.
GET /reporter/api/tests/<id>
Response
Response Status: 200 OK
[
{
"id": 2795,
"name": "quickStartFirefoxTest",
"startTime": 1578562056457,
"duration": 145440,
"status": "Failed",
"success": false,
"keyValuePairs": {
"date": "2020-01-09",
"test.type": "Web",
"maxScreenshotInterval": "0.0",
"cause": "no such element: Unable to locate element: {\"method\":\"xpath\",\"selector\":\"//button[@name='login']\"}",
"newSessionWaitTimeout": "60.0",
"acceptSslCerts": "true",
"goog:loggingPrefs": "{performance=ALL}",
"goog:chromeOptions": "{args=[disable-extensions, start-fullscreen, disable-web-security, disable-features=NetworkService, --window-size=1920,1080], prefs={download.directory_upgrade=true, safebrowsing_for_trusted_sources_enabled=false, profile.default_content_settings.popups=0",
"newCommandTimeout": "1200.0",
"browserVersion": "78.0.3904.108",
"browserName": "chrome",
"os.name": "Windows 10",
"javascriptEnabled": "true",
"platformName": "WIN10",
"test.framework": "Selenium",
"user": "assafm",
"testName": "quickStartFirefoxTest"
},
"testAttachments": [
{
"id": 12765,
"filePath": "/attachments/1/2020-01-09/2795/testreportfadfdf1b69bf185a825a5aeb556d1d7876785376898260938183611384077293385164/index.html",
"captionName": "",
"type": "zip",
"size": 4311336
}
],
"hasReport": true
}
]
Get Test By ProjectName - ID
Test with a specified id of the specified selected project.
This API is available for all user roles with permission to access the desired project.
GET /reporter/api/tests/<id>/project/<projectName>
Response
Response Status: 200 OK
[
{
"id": 2795,
"name": "quickStartFirefoxTest",
"startTime": 1578562056457,
"duration": 145440,
"status": "Failed",
"success": false,
"keyValuePairs": {
"date": "2020-01-09",
"test.type": "Web",
"maxScreenshotInterval": "0.0",
"cause": "no such element: Unable to locate element: {\"method\":\"xpath\",\"selector\":\"//button[@name='login']\"}",
"newSessionWaitTimeout": "60.0",
"acceptSslCerts": "true",
"goog:loggingPrefs": "{performance=ALL}",
"goog:chromeOptions": "{args=[disable-extensions, start-fullscreen, disable-web-security, disable-features=NetworkService, --window-size=1920,1080], prefs={download.directory_upgrade=true, safebrowsing_for_trusted_sources_enabled=false, profile.default_content_settings.popups=0",
"newCommandTimeout": "1200.0",
"browserVersion": "78.0.3904.108",
"browserName": "chrome",
"os.name": "Windows 10",
"javascriptEnabled": "true",
"platformName": "WIN10",
"test.framework": "Selenium",
"user": "assafm",
"testName": "quickStartFirefoxTest"
},
"testAttachments": [
{
"id": 12765,
"filePath": "/attachments/1/2020-01-09/2795/testreportfadfdf1b69bf185a825a5aeb556d1d7876785376898260938183611384077293385164/index.html",
"captionName": "",
"type": "zip",
"size": 4311336
}
],
"hasReport": true
}
]
Get Test By Manual Report Identifier (report_api_id)
Test with a specified Report API Id.
-
This API is available for all user roles.
-
By default
includeSteps
parameter isfalse
, and the test steps are not returned from the API call, user should addincludeSteps=true
to the REST API call in order to get the steps as well. -
The report_api_id is the "report_api_id" output parameter (A.K.A test plan id) that the client got from the start web-control API call.
GET /reporter/api/tests?report_api_id=<report_api_id>&includeSteps=true
Response Expand source
Response Status: 200 OK
{
"id": 31400,
"name": "Manual Report",
"startTime": "2021-06-27T14:06:03.241+0000",
"duration": 31642,
"status": "Passed",
"success": true,
"keyValuePairs": {
"date": "2021-06-27",
"device.majorVersion": "14",
"device.os": "iOS",
"report_api_id": "649d19f5-ce99-4ec2-9798-032c03deff9b",
"device.serialNumber": "5f1ab522dd414f0c97a8a5d724d60d0c1db10e83",
"device.version": "14.2",
"device.model": "iPhone 8",
"device.name": "B0231",
"device.manufacture": "Apple",
"user": "user",
"device.screenSize": "750x1334"
},
"testAttachments": [
{
"id": 184613,
"filePath": "/attachments/1/2021-06-27/31400/video63277793877005350553446619010767961978.mp4",
"filenameToOpen": null,
"originalFileName": null,
"captionName": null,
"type": "data_item",
"size": 847132
},
{
"id": 184615,
"filePath": "/attachments/1/2021-06-27/31400/executionPlanDeviceLog-27_06_2021_17_06_03-5f1ab522dd414f0c97a8a5d724d60d0c1db10e83-71983952068706984654385528224304717977.log",
"filenameToOpen": null,
"originalFileName": null,
"captionName": "",
"type": "log",
"size": 1045829
}
],
"count": null,
"minMergedSuccess": null,
"failedCount": null,
"hasReport": true,
"steps": [
{
"name": "Step 1",
"id": 1,
"startTime": 1624802764674,
"duration": 3864,
"description": "Step 1 description",
"expectedResult": "what should happen in step 1",
"actualResult": null,
"status": "PASSED",
"subSteps": [
{
"name": "Swipe from 1306,1876 to 452,1880",
"id": 2,
"startTime": 1624802764674,
"duration": 322
},
{
"name": "Swipe from 122,1642 to 856,1614",
"id": 3,
"startTime": 1624802766735,
"duration": 261
},
{
"name": "Swipe from 1360,1834 to 296,1760",
"id": 4,
"startTime": 1624802768271,
"duration": 267
}
]
},
{
"name": "Step 2",
"id": 5,
"startTime": 1624802773337,
"duration": 6935,
"description": "step 2 description",
"expectedResult": "What should happen in step 2",
"actualResult": null,
"status": "PASSED",
"subSteps": [
{
"name": "Click 150,2500",
"id": 6,
"startTime": 1624802773337,
"duration": 82
},
{
"name": "Click 726,1810",
"id": 7,
"startTime": 1624802775190,
"duration": 85
},
{
"name": "Click 714,1446",
"id": 8,
"startTime": 1624802775743,
"duration": 84
},
{
"name": "Click 772,1142",
"id": 9,
"startTime": 1624802776241,
"duration": 82
},
{
"name": "Click 784,710",
"id": 10,
"startTime": 1624802776719,
"duration": 100
},
{
"name": "{home}",
"id": 11,
"startTime": 1624802780272,
"duration": 0
}
]
},
{
"name": "Step 3",
"id": 12,
"startTime": 1624802785208,
"duration": 7213,
"description": "Step 3 description",
"expectedResult": "What should happen in step 3",
"actualResult": "Actual",
"status": "PASSED",
"subSteps": [
{
"name": "Swipe from 314,1218 to 1256,1156",
"id": 13,
"startTime": 1624802785208,
"duration": 164
},
{
"name": "Click 984,1622",
"id": 14,
"startTime": 1624802787559,
"duration": 100
},
{
"name": "Swipe from 950,2202 to 868,1334",
"id": 15,
"startTime": 1624802789417,
"duration": 220
},
{
"name": "Swipe from 910,1064 to 952,2250",
"id": 16,
"startTime": 1624802791211,
"duration": 235
},
{
"name": "{home}",
"id": 17,
"startTime": 1624802792421,
"duration": 0
}
]
}
]
}
Get Tests List
List the tests of the currently selected project given TestsRequest (filter, sort, limit, offset, keys to include) object sent.
This API is available for all user roles with permission to access the desired project.
POST /reporter/api/tests/list
POST /reporter/api/tests/list?projectId=<projectId>
POST /reporter/api/tests/list?projectName=<projectName>
- projectName - Name of the Project
- projectId - Project ID
JSON Parameter
Name | Type | Mandatory | Description |
---|---|---|---|
returnTotalCount | Boolean | No | Returns total record count, default false |
limit | Number | No | limit length or returned data |
page | Number | No | Starting at 1 |
searchValue | String | No | Return test views which name contains this value, case insensitive |
Sort | List | No | Sort by given properties. format : [ { "property": "fieldName", "descending": false }, ... ] |
filter | List | No | Filter by given properties. format : [ { "property":"fieldName or key", "operator": "=", "value": "string value"}, ... ] |
keys | List | No | keys to be included in the response else only test's fixed columns returned format : "keys": [ "key1", "key2", ...] |
Response
Response Status: 200 OK
[
{
"count": 2795,
"data": [
{
"test_id": 3,
"name": "Quick Start iOS Native Demo",
"start_time": 1571202942000,
"duration": 13057,
"status": "Incomplete",
"status_code": 2,
"success": false,
"attachments_size": 0,
"attachment_count": 0,
"has_attachment": "N",
"date": "2019-10-16"
},
{
"test_id": 149,
"name": "adb restriction test",
"start_time": 1571719774473,
"duration": null,
"status": "Incomplete",
"status_code": 2,
"success": false,
"attachments_size": null,
"attachment_count": 0,
"has_attachment": "N",
"date": "2019-10-22"
},
...
]
Get Tests Grouped
Returns groupedcounts from tests givenTestsRequest(filter, sort, keys to group by, pivot by for counts: such success and/or status_code) object sent.
This API is available for alluser roles with permission to access the desired project.
POST /reporter/api/tests/grouped
POST /reporter/api/tests/grouped?projectId=<projectId>
POST /reporter/api/tests/grouped?projectName=<projectName>
- projectName - Name of the Project
- projectId - Project ID
JSON Parameter
Name | Type | Mandatory | Description |
---|---|---|---|
returnTotalCount | Boolean | No | return total record count, default false |
pivotBy | List | No | string array which can contain "success" and/or "status".: "success" adds two columns to each result"successCount" and "unsuccessCount". "status" adds tree columns: "passedCount", "failedCount", "incompleteCount". |
keys | List | No | property are the keys used to "group by". |
All resulting rows include the column "count" along "pivotBy" columns if any.
Response
Response Status: 200 OK
[
{
"count": 1,
"data": [
{
"_count_": 2795
}
]
}
]
Get a Distinct Key Value
Returns distinct key values from tests given TestsRequest(filter, sort) object sent.
JSON Parameter
Name | Type | Mandatory | Description |
---|---|---|---|
keys | List | Yes | Return key values based on this list |
This API is available for Cloud Administrators, and Project Administrators with permission to access the desired project.
POST /reporter/api/tests/distinct
POST /reporter/api/tests/distinct?projectId=<projectId>
POST /reporter/api/tests/distinct?projectName=<projectName>
-
projectName - Name of the Project
-
projectId - Project ID
JSON Parameter
Name | Type | Mandatory | Description |
---|---|---|---|
keys | List | Yes | Return key values based on this list |
Response
Response Status: 200 OK
[
{
"data": [
{
"date": "1911-7-3",
"device.os": null,
"device.version": null,
"key008": "",
"test_id": 1390
},
{
"date": "1911-7-3",
"device.os": null,
"device.version": null,
"key008": "",
"test_id": 1395
},
{
"date": "1911-7-3",
"device.os": null,
"device.version": null,
"key008": "",
"test_id": 1396
},
{
"date": "1911-7-3",
"device.os": null,
"device.version": null,
"key008": "",
"test_id": 1398
},
. . .
]
GET CSV File
Get tests in CSV format given TestsRequest (filter, sort, limit, offset, keys to include).
This API is available for all user roles.
GET /reporter/api/tests/csv?request=<TestRequest>
GET /reporter/api/tests/csv?request=<TestRequest>&projectId=<projectId>
GET /reporter/api/tests/csv?request=<TestRequest>&projectName=<projectName>
- projectName - Name of the Project
- projectId - Project ID
JSON Parameter
Name | Type | Mandatory | Description |
---|---|---|---|
keys | List | Yes | Return key values based on this list |
Request
{
"returnTotalCount": true,
"limit": 10,
"page": 1,
"sort": [],
"keys": [
"date",
"device.os",
"device.version"
],
"filter": [
{
"property": "date",
"operator": "=",
"value": "2020-01-05"
}
]
}
Delete Test
Deletes the desired tests, payload is an array of ID of the tests to be deleted, for example: [ 5, 67, 100 ]
This API is available for all user roles with permission to access the desired project.
POST /reporter/api/tests/delete
POST /reporter/api/tests/delete?projectId=<projectId>
POST /reporter/api/tests/delete?projectName=<projectName>
- projectName - Name of the Project
- projectId - Project ID
Body Parameter
Type | Mandatory | Description |
---|---|---|
List | Yes | An array of the ID of the tests to be deleted, for example: [ 5, 67, 100 ] |
Download Attachments
Download all the attachments of testId
as a zip file.
The filename of the exported attachments is test_id_<testId>_attachments.zip
This API is available for all user roles with permission to access the desired project.
GET /reporter/api/<testId>/attachments
testId - ID of the required test.
Code Examples
These examples use the Unirest HTTP library. To compile and run them, use the following Maven dependency:
Maven dependency
<dependency>
<groupId>com.mashape.unirest</groupId>
<artifactId>unirest-java</artifactId>
<version>1.4.9</version>
</dependency>
Java Expand source
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.JsonNode;
import com.mashape.unirest.http.Unirest;
import com.mashape.unirest.http.exceptions.UnirestException;
import org.apache.http.HttpHeaders;
import org.junit.Test;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.file.Files;
import java.io.InputStream;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Objects;
public class APIConfluenceTests {
private HttpResponse<String> responseString;
private HttpResponse<InputStream> responseInputStream;
private String urlBase = "http://hostname:port/"; //TODO: modify hostname and port of your Reporter
private String user = "user"; //TODO: user name
private String password = "....."; //TODO: user password
private String accessKey= "....."; //TODO: user access key
String projectName = "projectName";//TODO: project name is here
String projectID = "projectID";//TODO: project ID is here
private String testID = "test ID";//TODO: test ID is here
@Test
public void getSpecifiedTest() {
String url = urlBase + "/api/tests/" + testID;
try {
responseString = Unirest.get(url)
.basicAuth(user, password)
.header("content-type", "application/json")
.asString();
System.out.println(responseString.getBody());
} catch (Exception e) {
e.printStackTrace();
}
}
@Test
public void getTestsByProjectName() {
String url = urlBase + "/api/tests/" + testID + "/project/" + projectName + "/";
try {
responseString = Unirest.get(url)
.basicAuth(user, password)
.header("content-type", "application/json")
.asString();
System.out.println(responseString.getBody());
} catch (Exception e) {
e.printStackTrace();
}
}
@Test
public void TestsList() {
String url = urlBase + "/api/tests/list";
HttpResponse<JsonNode> response = null;
try {
response = Unirest.post(url)
.basicAuth(user, password)
.header("Content-Type", "application/json")
.body("{\"returnTotalCount\":true, \"limit\":10, \"page\":1, \"sort\":[{\"property\":\"test_id\",\"descending\":false}],\r\n" +
" \"keys\":[\"date\",\"device.os\",\"device.version\"],\r\n" +
" \"filter\":[{\"property\":\"device.os\",\"operator\":\"=\",\"value\":\"iOS\"}]}")//TODO: insert key and value
.asJson();
} catch (UnirestException e) {
e.printStackTrace();
}
if (Objects.nonNull(response)) {
System.out.println(response.getBody());
}
}
@Test
public void getGroupedCounts() {
String url = urlBase + "/api/tests/grouped";
try {
String body = "{\"returnTotalCount\":true, \"limit\":10, \"page\":1,\r\n" +
" \"keys\":[\"date\",\"device.os\",\"device.version\"],\r\n" +
" \"filter\":[{\"property\":\"date\",\"operator\":\"=\",\"value\":\"2020-01-05\"}]}";
responseString = Unirest.post(url)
.basicAuth(user, password)
.header("content-type", "application/json")
.body(body)//TODO: insert key and value
.asString();
System.out.println(responseString.getBody());
} catch (Exception e) {
e.printStackTrace();
}
}
@Test
public void getDistinctKey() {
String url = urlBase + "api/tests/distinct";
try {
String body = "{\"returnTotalCount\":true, \"limit\":10, \"page\":1," +
" \"sort\":[{\"property\":\"test_id\",\"descending\":false}],\r\n" +
" \"keys\":[\"date\",\"device.os\",\"device.version\",\"test_id\"],\r\n" +
" \"filter\":[{\"property\":\"date\",\"operator\":\"=\"," + "\"value\":\"2020-01-05\"}]" +
"}";
responseString = Unirest.post(url)
.basicAuth(user, password)
.header("content-type", "application/json")
.body(body)//TODO: insert key and value
.asString();
System.out.println(responseString.getBody());
} catch (Exception e) {
e.printStackTrace();
}
}
@Test
public void getCSV() {
String url = urlBase + "/api/tests/csv";
try {
String request="{\"returnTotalCount\":true, \"limit\":10, \"page\":1," +
" \"sort\":[],\r\n" +
" \"keys\":[\"date\",\"device.os\",\"device.version\"],\r\n" +
" \"filter\":[{\"property\":\"date\",\"operator\":\"=\"," + "\"value\":\"2020-01-05\"}]" +
"}";
responseString = Unirest.get(url)
.basicAuth(user, password)
.header("content-type", "application/json")
.queryString("request",request)
.queryString("projectId","1")
.queryString("projectName","Default")
.asString();
System.out.println(responseString.getBody());
} catch (Exception e) {
e.printStackTrace();
}
}
@Test
public void deleteTests() {
String url = urlBase + "api/tests/delete";
try {
responseString = Unirest.post(url)
.basicAuth(user, password)
.queryString("projectId","1")
.header("content-type", "application/json")
.body("[<testID1>,<testID2>,...]") //TODO: insert test id list to be deleted
.asString();
} catch (Exception e) {
e.printStackTrace();
}
}
@Test
public void getAttachmentsByTestID() {
String url = urlBase + "/api/" + testID + "/attachments";
try {
responseInputStream = Unirest.get(url)
.basicAuth(user, password)
.header("content-type", "application/json")
.asBinary();
String destination = "destination";//TODO: Path to save the file - zip file
writeToFile(destination);
} catch (Exception e) {
e.printStackTrace();
}
}
private void writeToFile(String destination) {
InputStream inputStream = responseInputStream.getRawBody();
try {
FileOutputStream fileOutputStream = new FileOutputStream(destination);
int bytesRead = -1;
byte[] buffer = new byte[4096];
while ((bytesRead = inputStream.read(buffer)) != -1) {
fileOutputStream.write(buffer, 0, bytesRead);
}
fileOutputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}