Rest API - TestView
The Reporter provides you with a Rest API that gives you direct access to the test data and statistics.
For more information see Test View.
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:
{device.os: Android}
-
Project - Concept derived from the cloud. Each project has it's own resources (users, devices) and can be used to created separation of testing efforts.
-
Test - Single test execution instance.
The role of the user performing the Rest Operation is specified by the Authorization header. For a detailed example, see How To Execute Rest API.
Get Test View Groups
List all test views of the currently selected project.
Test View's returned properties:
- id : ID of the test view group.
- name : Name of the test view group.
- byKey : Key name selected in "View by" panel.
- createdBy : User who created the test view group.
- showInDashboard : Is the "add to dashboard" button enabled.
This API is available for all user roles.
GET /reporter/api/testView
Response
Response Status: 200 OK
[
{
"name": "Android OS",
"id": 54,
"createdBy": "admin",
"byKey": "date"
},
{
"name": "Default",
"id": 50,
"byKey": "date",
"showInDashboard": true
},
...
]
Create Test Views Group
Creates a full test view.
This API is available for all user roles.
POST /reporter/api/testView
JSON Parameter
Name | Type | Mandatory | Description |
---|---|---|---|
name | String | Yes | Name of the newly created test view group |
byKey | String | Yes | The key name selected in the "View by" panel. |
groupByKey1 | String | Yes | The key name selected in "Group by" left panel |
groupByKey2 | String | Yes | The key name selected in "Group by" right panel |
keys | List | No | keys to be included in the newly created test views group |
showInDashboard | Boolean | No | Show the test views group in the dashboard ( default value is false) |
Response
Response Status: 200 OK
{
"id": 56,
"name": "newTestViewsGroup",
"byKey": "date",
"byKeyDesc": true,
"groupByKey1": "device.os",
"groupByKey2": "device.version",
"filter": [],
"keys": [
"date",
"app"
],
"createdBy": "admin"
}
Update Test Views Group
Updates selected properties of the test view.
This API is available for all user roles with permission to access the desired project.
PUT /reporter/api/testView
JSON Parameter
Name | Type | Mandatory | Description |
---|---|---|---|
id | Number | Yes | ID of the test view group |
name | String | No | The new name of the test view group |
showInDashboard | Boolean | No | Show the test views group in the dashboard ( default value is false) |
Response
Response Status: 200 OK
{
"id": 56,
"name": "newTestViewsGroup",
"byKey": "date",
"byKeyDesc": true,
"groupByKey1": "device.os",
"groupByKey2": "device.version",
"filter": [],
"keys": [
"date",
"app"
],
"createdBy": "admin"
}
Get Filtered Test Views
Show list of test views of the currently selected project based on given properties.
Test View's returned properties:
- count: Number shows the total count of records.
- data: List holds data of each test views as JSON contains the following properties:
-
id: Id of the test view group.
-
name: Name of the test view group.
-
byKey : Key name selected in "View by" panel.
-
createdBy: User who created the test view group.
-
showInDashboard: Is the "add to dashboard" button enabled.
-
This API is available for all user roles with permission to access the desired project.
POST /reporter/api/testView/list
JSON Parameter
Name | Type | Mandatory | Description |
---|---|---|---|
limit | Number | Yes | limit length or returned data |
page | Number | Yes | Starting at 1 |
Sort | List | No | Sort by given properties. format : [ { "property": "fieldName", "descending": false }, ... ] |
searchValue | String | No | Return test views which name contains this value, This is case insensitive. |
Response
Response Status: 200 OK
{
"count": 2,
"data": [
{
"name": "Android OS",
"id": 54,
"createdBy": "admin",
"byKey": "date"
}
]
}
Get Test View
Retrieves the test view by its ID.
Returns the full test view entities.
This API is available for all user roles with permission to access the desired project.
GET /reporter/api/testView/<id>
id - ID of the test view group
Response
Response Status: 200 OK
{
"id": 54,
"name": "Android OS",
"byKey": "date",
"byKeyDesc": true,
"groupByKey1": "device.os",
"groupByKey2": "device.version",
"filter": [
{
"id": 50,
"testViewId": 54,
"operator": "=",
"value": "Android",
"isByKey": false,
"isStatus": false,
"persisted": true,
"property": "device.os"
}
],
"keys": [
"date",
"device.os",
"device.version"
],
"createdBy": "admin"
}
Get Test Counts
Retrieves test counts of the test view given by its ID.
This API is available for all user roles with permission to access the desired project.
GET /reporter/api/testView/<id>:summary
id - ID of the test view group.
Parameters
Name | Type | Mandatory | Description |
---|---|---|---|
filter | JSON | No | Filter by test view's name. value example : {"device.os":"Android"} |
Response
Response Status: 200 OK
{
"data": [
{
"passedCount": 2,
"failedCount": 0,
"incompleteCount": 0,
"skippedCount": 0,
"_count_": 2
}
]
Delete Test View
Deletes the test view identified by its ID.
This API is available for all user roles with permission to access the desired project.
DELETE /reporter/api/testView/<id>
id - ID of the test view group.
Code Example
The examples below 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 org.junit.After;
import org.junit.Before;
import org.junit.Test;
import com.mashape.unirest.http.Unirest;
import static org.junit.Assert.fail;
import com.mashape.unirest.http.HttpResponse;
import java.io.InputStream;
public class REST_API_testView {
private HttpResponse<String> responseString;
private String urlBase = "HOSTNAME"; //TODO: modify hostname and port of your Reporter
private String user = "<USERNAME>"; //TODO: user name
private String password = "<PASSWORD>"; //TODO: user password
private String accessKey= "<ACCESS_KEY>"; //TODO: user access key
String projectName = "<Project Name>";//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 get_testView() {
String url = urlBase + "/api/testView";
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 create_testView() {
String url = urlBase + "/api/testView";
try {
responseString = Unirest.post(url)
.basicAuth(user, password)
.header("content-type", "application/json")
.body("{\n" +
" \"name\": \"newTestView\",\n" +
" \"byKey\":\"date\",\n" +
" \"groupByKey1\": \"device.os\",\n" +
" \"groupByKey2\": \"device.os\",\n" +
" \"showInDashboard\": true,\n" +
" \"viewBy\": \"data\"\n" +
"\n" +
"}")
.asString();
System.out.println(responseString.getBody());
} catch (Exception e) {
e.printStackTrace();
fail("Failed in REST API");
}
}
//****************************************************************************************************************//
@Test
public void update_testView() {
String url = urlBase + "/api/testView";
try {
responseString = Unirest.put(url)
.basicAuth(user, password)
.header("content-type", "application/json")
.body("{\n" +
" \"id\":1051,\n" +
" \"name\":\"newTestViewName\",\n" +
" \"showInDashboard\": true\n" +
"}")
.asString();
System.out.println(responseString.getBody());
} catch (Exception e) {
e.printStackTrace();
fail("Failed in REST API");
}
}
//****************************************************************************************************************//
@Test
public void filter_testView() {
String url = urlBase + "/api/testView/list";
try {
responseString = Unirest.post(url)
.basicAuth(user, password)
.header("content-type", "application/json")
.body("{\n" +
" \"limit\":2,\n" +
" \"page\": 1,\n" +
" \"searchValue\":\"def\"\n" +
"}")
.asString();
System.out.println(responseString.getBody());
} catch (Exception e) {
e.printStackTrace();
fail("Failed in REST API");
}
}
//****************************************************************************************************************//
@Test
public void get_testView_by_id() {
String url = urlBase + "/api/testView/"+1051;
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 get_testView_count() {
String url = urlBase + String.format("/api/testView/%d/summary",1051);
try {
responseString = Unirest.get(url)
.basicAuth(user, password)
.header("content-type", "application/json")
.queryString("filter","{\"device.os\":\"Android\"}")
.asString();
System.out.println(responseString.getBody());
System.out.println("done");
} catch (Exception e) {
e.printStackTrace();
}
}
//****************************************************************************************************************//
@Test
public void delete_testView_count() {
String url = urlBase + String.format("/api/testView/%d",1151);
try {
responseString = Unirest.delete(url)
.basicAuth(user, password)
.header("content-type", "application/json")
.asString();
System.out.println(responseString.getBody());
} catch (Exception e) {
e.printStackTrace();
}
}
}