TestProject Addons

RESTful API Client

This Addon provides actions to to send HTTP/S requests using GET, POST, PUT and DELETE methods.

Actions

There are 5 actions in this Addon:

  • HTTP GET Request

  • HTTP POST Request

  • HTTP PUT Request

  • HTTP DELETE Request

  • HTTP PATCH Request

Fields

Field/Action

Required

Input/Output

GET

POST

PUT

DELETE

PATCH

uri

X

INPUT

X

X

X

X

X

query

INPUT

X

X

X

X

X

headers

INPUT

X

X

X

X

X

body

INPUT

X

X

X

X

X

format

INPUT

X

X

X

X

X

jsonPath

INPUT

X

X

X

X

X

expectedStatus

INPUT

X

X

X

X

X

schenaPath

INPUT

X

X

X

X

X

headerDelimiter

INPUT

X

X

X

X

X

filePath

INPUT

X

X

X

response

OUTPUT

X

X

X

X

X

status

OUTPUT

X

X

X

X

X

responseHeaders

OUTPUT

X

X

X

X

X

jsonSchemaValidation

OUTPUT

X

X

X

X

X

Input Fields

  • uri - Request URL (endpoint)

    This is a mandatory parameter, otherwise action will fail.

    This parameter should contain only the schema, hostname, path and port (e.g. https://domain.tld:8080/api) It should not contain query parameters (e.g. ?a=1&b=2).

  • query - Query parameters.

    For example:

    If your request query parameters needs to be a=1 and b=2, then write in this field a=1&b=2

    The & symbol is used to separate between each parameter.

  • headers - Request headers. The following default headers are sent:

    accept: text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2
    connection: keep-alive
    content-length:
    content-type: application/json
    host: The host
    user-agent: Jersey/2.22.1 (HttpUrlConnection 1.8.0_181)

    Note: the default headers listed above are not overwritten if you don't specify them.

    The list of headers are separated by commas (,).

    For example:

    If your request headers needs to be connection=keep-alive and content-type=application/json, then write in this field:

    connection=keep-alive,content-type=application/json

    • Note: You can delimit the headers with a different character by using the HeaderDelimiter field.

  • body- Body that will be sent in the request

  • format- Body (if provided) format. For example: application/json or text/html, etc...

    For a complete list of options refer to: https://en.wikipedia.org/wiki/Media_type

  • expectedStatus - If this parameter is set, the action will check if the actual status code equals expected status code.

    If the actual status code is not the expected status code then action fail. Accepted values are numbers between 100 and 599 (1xx - 5xx).

  • HeaderDelimiter - This parameter is used to decide the character to delimit the headers around, by default '=' will be used.

  • jsonPath - This parameter is used to extract nodes or value from server's JSON response (if such is available).

    Supported syntax is the Jayway JsonPath syntax. You can find a complete documentation for Jayway JsonPath at GitHub

    For a specific example, see Example 1.2

    If the value specified is not found or the the response is a non-JSON response, action will fail.

  • ignoreUntrustedCertificate - This parameter is used to disable the verification of SSL certificate.

    Parameter is false by default. If set to true, RESTful client will accept self signed and untrusted SSL certificate presented by the server when sending a request.

  • schemaValidationOutputFilePath - This parameter is the file path for the result of the JSON schema validation.

    If empty, it will create the output file in the system's Downloads directory.

  • schemaPath - This parameter is the path for the JSON Schema file.

    This parameter is for a full* path of a local schema file, or a URL pointing to a remote schema file. If a URL is provided, it will download the schema locally to a temporary file, before performing the validation. Schema validation is performed on the JSON response object provided in the JsonResponse field.

  • createFile - This parameter is a boolean flag to indicate that a validation results output is required.

    If set totrue, and the schemaValidationOutput parameter is set, a file holding the validation result will be created in the provided location.

  • filePath - This parameter is the full path of a local file which should be sent to the designated endpoint using POST, PUT, or PATCH. if this parameter is set, the file will be sent as multipart/form-data format, you can still supply a separate body and body format to the request.

Output Fields

  • response - The full response from the server or the extracted node/value found using expression specified in jsonPath parameter.

    If jsonPath is set, response will be limited to the node/value found using the provided expression. If the value specified is not found or the the response or the response is not a valid JSON, this field will be empty.

  • jsonResponse - The full response from the server or the extracted node/value found using expression specified in jsonPath parameter as a JSON object.

    This parameter holds the whole response body, or the node/property requested via jsonPath as a JSON object.

  • status - Server's response status that is a number between 100 and 599 (1xx - 5xx).

  • schemaValidationOutput - This parameter is the output parameter for the schema validation.

    This parameter will contain the output of any violations in the JSON file according to the provided schema.

Using Parameters

By using parameters in your rest API calls, you will be able to pass information between test steps like bearer tokens, API keys and server responses and create data driven tests (utilizing CSV files).

Parameters on rest API tests are avilbale on any input fields.

To create/select a parameter, simply select the input field and click on Select parameter:

From the Parameters menu, you can create a new parameter or select existing ones to use in your steps.

Project parameters are shared across all your tests, and test variables are set per test

You will easily be able to chain requests and transfer data from one request to another, like shown in Examples 13-15, by saving the response of the POST request, we receive the URL to use in the next PUT request.

Results

Failure Criteria

All actions have several criterias that may result in failure assertion:

  • When expectedStatus does not match the actual response status:

    Note: If the expectedStatus is not set, and the server responds with status other than 1xx, this will not be considered a failure.

  • When the requested node/value by jsonPath is not found in the response.

  • When the server fails to respond.

  • Connectivity errors

Result Description

All actions will report a message with the following information, no matter if the action pass or fail:

  • Server response status (taken from the status field)

  • Response body or “No body/value was returned by the server” when it's absent.

  • Report of violations discovered using provided JSON schema, or a statement that none were found.

Examples

Following TestProject platform conventions, unset parameters will be treated as nulls / empty strings and won't be used.

If the format field is empty it will take application/json as the default value.

Example 1: POST Request with body

Field

Value

Input/Output

uri

https://jsonplaceholder.typicode.com/posts/1

INPUT

body

{"name": "Example User", "email": "[email protected]", "username": "ExampleUser"}

INPUT

response

{"name": "Example User", "email": "[email protected]", "username": "ExampleUser", "id": 11}

OUTPUT

status

201

OUTPUT

Action result: PASSED

Example 1.1: POST Request with expectedStatus

Field

Value

Input/Output

uri

https://jsonplaceholder.typicode.com/posts/1

INPUT

body

{"name": "Example User", "email": "[email protected]", "username": "ExampleUser"}

INPUT

response

{"name": "Example User", "email": "[email protected]", "username": "ExampleUser", "id": 11}

OUTPUT

status

201

OUTPUT

expectedStatus

200

Action result: FAILED (Due to expectedStatus that does not much status)

Example 1.2: POST Request with jsonPath

Field

Value

Input/Output

uri

https://jsonplaceholder.typicode.com/posts/1

INPUT

body

{"name": "Example User", "email": "[email protected]", "username": "ExampleUser"}

INPUT

jsonPath

name

INPUT

response

ExampleUser

OUTPUT

status

201

OUTPUT

Action result: PASSED

Example 2: GET Request

Field

Value

Input/Output

uri

https://jsonplaceholder.typicode.com/posts/1

INPUT

query

postId=1&id=1

INPUT

response

{"postId": 1, "id": 1, "name": "SOME_USER_NAME", "email": "SOME_EMAIL", "body": "SOME_BODY"}

OUTPUT

status

200

OUTPUT

Action result: PASSED

Example 3: DELETE Request

Field

Value

Input/Output

uri

https://jsonplaceholder.typicode.com/posts/1

INPUT

headers

Authorization=YOUR_API_TOKEN,Host=jsonplaceholder.typicode.com

INPUT

response

OUTPUT

status

200

OUTPUT

Action result: PASSED

Example 4: POST Request to Upload a text file to a web server using API Key in headers

Field

Value

Input/Output

uri

https://jsonplaceholder.typicode.com/posts

INPUT

filePath

/files/users.txt

INPUT

headers

Authorization=API_KEY

INPUT

response

{"messsage":"Users updated"}

OUTPUT

status

200

OUTPUT

Field

Value

Input/Output

uri

https://api.testproject.io/v2/projects/{projectid}/applications/{appid}/file/upload-link

INPUT

headers

Authorization=API_KEY

INPUT

jsonPath

$.url

INPUT

response

URL to upload the APK/IPA to TestProject

OUTPUT

status

200

OUTPUT

Example 6: PUT Request to upload an APK to TestProject using TestProject Restful API

Field

Value

Input/Output

uri

URL From the previous Example

INPUT

filePath

Local path to file e.g. C:\files\application.apk

INPUT

status

200

OUTPUT

Files are sent as multipart/form data, additional body and body format can be supplied to the request.

Example 7: POST Request to confirm file upload with BODY

Field

Value

Input/Output

uri

https://api.testproject.io/v2/projects/{projectid}/applications/{appid}/file

INPUT

headers

Authorization=API_KEY

INPUT

body

{"fileName": "Enter-the-desired-file-name-here.apk/ipa"}

INPUT

status

200

OUTPUT

Example 8: POST Request using GraphQL

Field

Value

Input/Output

uri

https://graphql.anilist.co

INPUT

body

{"query": "query ($id: Int) {Media(id: $id, type: ANIME) { id title {romaji english native}}}"}

INPUT

format

application/graphql

INPUT

response

{ "data": { "Media": { "id": 1, "title": { "romaji": "Cowboy Bebop", "english": "Cowboy Bebop", "native": "カウボーイビバップ" } } } }

OUTPUT

response

200

OUTPUT

To use GraphQL, you must supply all Mutations/Queries as a valid JSON format.

Example 9: POST Request with application/x-www-form-urlencoded format

Field

Value

Input/Output

uri

https://jsonplaceholder.typicode.com/posts/1

INPUT

body

grant_type=password&password=test&client_id=test&[email protected]

INPUT

format

application/x-xxx-form-urlencoded

INPUT

response

{"token":"1234"}

OUTPUT

status

200

OUTPUT

'application/x-www-form-urlencoded'body requires to be in key=value format where each key-value pair is chained with &

Example 10: POST Request with API Key in Query Params

Field

Value

Input/Output

uri

https://jsonplaceholder.typicode.com/posts

INPUT

query

apikey=1234&username=test&password=project

INPUT

body

{"postsId":"15"}

INPUT

status

201

OUTPUT

Example 11: POST Request with Basic Auth with Bearer Token

Field

Value

Input/Output

uri

https://jsonplaceholder.typicode.com/posts

INPUT

headers

Authorization= Basic {base64encoded)

INPUT

status

200

OUTPUT

To use Basic Auth, the token needs to be encoded to Base64 prior to running the step, you can easily do that using the Base64 encode action which you can see here.

Example 12: POST Request with Basic Auth using username and password with Raw format

Field

Value

Input/Output

uri

https://jsonplaceholder.typicode.com/posts

INPUT

query

username=test&password=project

INPUT

body

This is a test

INPUT

format

application/raw

INPUT

status

201

OUTPUT

By Parameterizing your tests, we can use previous responses as future inputs, like API keys, bearer tokens, and much more.

Example 13: GET Request with parameters in Headers and Query field

Field

Value

Input/Output

uri

https://jsonplaceholder.typicode.com/users

INPUT

query

username={username}&password={password}

INPUT

headers

Authorization={api_key}

INPUT

response

{"user":"Test", "ID:1}

OUTPUT

status

200

OUTPUT

Text in curly brackets {} represents Parameters in TestProject recorded tests

Example 14: POST Request with parameters in the body field

Field

Value

Input/Output

uri

https://jsonplaceholder.typicode.com/posts

INPUT

body

{ "username":"{username}", "password":"{userpassword}"}

INPUT

status

201

OUTPUT

response

{"message": "user created"}

OUTPUT

Example 15: POST Request with Parameters in the Body, head and URI

Field

Value

Input/Output

uri

https://jsonplaceholder.typicode.com/posts/{post_id}

INPUT

headers

Authorization={api_key}

INPUT

body

{ "username":"{username}", "password":"{password}"}

INPUT

status

201

OUTPUT

Valid Schema Format

Below is an example of a valid schema format:

{
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "https://reqres.in/api/users?page=2/users.schema.json",
"title": "users",
"description": "A user from list",
"type": "object",
"properties": {
"name": {
"description": "The name for a user",
"type": "string"
}
},
"required": [ "name" ]
}

This is also a good source for a schema: https://json-schema.org/learn/getting-started-step-by-step.html