When you create an API test, the Test Steps page shows various fields like :
Group Name : It simply groups all the actions performed within one single HTTP request into a single group.
An Endpoint URL : An application implementing a RESTful API will define one or more URL endpoints with a domain, port, path, and/or query string
For example,https://mydomain/user/123?format=json
.Authentication : If an API requires authentication, the API Authentication can be created under “Configure” section (on the left pane) & used in the API test case.
The API Authentications once created under the “Configure” section, are displayed under the authentication dropdown in the API test.The HTTP method : Different HTTP methods can be used on any endpoint which map to application create, read, update, and delete operations.
There are various HTTP requests available in BQ Platform. They are :GET
POST
PUT
PATCH
DELETE
HEAD
HTTP headers : Information such as authentication token or cookies can be contained in the HTTP request header.
Query String : Query string parameters appear after a question mark (
?
) in the endpoint URL.
The parameters and their values (displayed after the question mark) are referred to as the “query string.”
In the query string, each parameter is listed one after the other with an ampersand (&
) separating them.
The order of the query string parameters does not matter.
For example :/surfreport/{beachId}?days=3&units=metric&time=1400
The query string parameters in the above endpoint are :days=3
,units=metric
andtime=1400
Body Data : Data is normally transmitted in the HTTP body in an identical way to HTML <form> submissions or by sending a single JSON-encoded data string.
Extract and Store : When an HTTP request is made, data from the response can be retrieved, extracted and stored in a variable for further use.
Assertions : Assertions is nothing but verification performed on the endpoint URL.
When & how to use the HTTP(S) Requests ?
GET Request
The HTTP GET request is used to retrieve requested data from a server. The data is identified by a unique URI (Uniform Resource Identifier).
A GET request can pass parameters to the server using "Query Parameters".
Example :
Suppose we wish to make a GET request to the endpoint url : https://reqres.in/api/users?page=2
We will enter the url https://reqres.in/api/users ( value before “?” ) in the URL field & pass the query string value page=2 under “Query Parameters” tab.
When you execute this test, data will be fetched and displayed in the local Executor window.
Status 200 OK is displayed for the HTTP GET request.
Status 200 OK means that the requested data has been fetched correctly.
Info |
---|
There may be cases when GET request may be unsuccessful. |
If you scroll down, you will notice that the data retrieved, is on the basis of the query string data passed under the “Query Parameter“ tab.
POST Request
The HTTP POST request method is meant to create new data on a server.
A POST request can pass parameters to the server using "Query Parameters" as well as the “Body Parameters”.
There are three ways in which you can pass the POST Request data under the Body Parameter :
form-data
x-www-form-urlencoded
raw
Info |
---|
You can check the meaning of HTTP Status Messages here : https://www.w3schools.com/tags/ref_httpmessages.asp |
Let us understand their usage better with the help of an example.
Form-data :
Form-data is used while passing the data for filling various forms & non-private data.
The data is passed as key-value pair.
For Example :Suppose we wish to make a POST request to the url : https://app.bqurious.com/j_spring_security_check
When you execute this test, data will be fetched and displayed in the local Executor window.
Status is displayed for the HTTP POST request
x-www-form-urlencoded :
x-www.form-urlencoded is used while passing the private data.
The data is passed as key-value pair.
For Example :
Suppose we wish to make a POST request to the url : https://postman-echo.com/postWhen x-www-form-urlencoded is selected as type under the Body Parameter, the Content-Type is automatically updated under the “Header Parameter” tab.
raw :
raw is used to pass various data like JSON, javascript, XML, HTML etc.
Content Types available under “Body Parameters” tab:Text (text/plain)
For Example :Suppose you select the Content Type as Text (text/plain) while passing the data under “Body Parameters” tab.
When you execute this test, data will be fetched and displayed in the local Executor window.
If you scroll down, you will notice :Status 201 Created is displayed for the HTTP POST request
JSON (application/json)
For Example :
Let us assume that you wish to send a POST request to endpoint https://reqres.in/api/usersSuppose you select the Content Type as JSON (application/json) while passing the data under “Body Parameters” tab.
When you execute this test, data will be fetched and displayed in the local Executor window.
If you scroll down, you will notice :Status 201 Created is displayed for the HTTP POST request
Key 'createdAt' is displayed in response
Javascript (application/javascript)
For Example :Suppose you select the Content Type as Javascript (application/javascript) while passing the data under “Body Parameters” tab.
When you execute this test, data will be fetched and displayed in the local Executor window.
If you scroll down, you will notice :Status 201 Created is displayed for the HTTP POST request
XML (application/xml)
For Example :Suppose you select the Content Type as XML (application/xml) while passing the data under “Body Parameters” tab.
When you execute this test, data will be fetched and displayed in the local Executor window.
If you scroll down, you will notice :Status 201 Created is displayed for the HTTP POST request
Text XML (text/xml)
For Example :Suppose you select the Content Type as Text XML (text/xml) while passing the data under “Body Parameters” tab.
When you execute this test, data will be fetched and displayed in the local Executor window.
If you scroll down, you will notice :Status 201 Created is displayed for the HTTP POST request
HTML (text/html)
For Example :Suppose you select the Content Type as HTML (text/html) while passing the data under “Body Parameters” tab.
When you execute this test, data will be fetched and displayed in the local Executor window.
If you scroll down, you will notice :Status 201 Created is displayed for the HTTP POST request
PATCH Request
The HTTP PATCH method is used to update resources on a server.
PATCH request supports both “Query Parameters” and “Body Parameters”.
For Example :
Let us assume that you wish to send a PATCH request to endpoint https://reqres.in/api/users/2
Also, lets us assume that the data passed during POST request was :
Suppose you select the Content Type as JSON (application/json) while passing the data under “Body Parameters” tab.
When you execute this test, data will be fetched and displayed in the local Executor window.
If you scroll down, you will notice :
Status is displayed for the HTTP PATCH request
Updated data is displayed in response
Key ‘updatetdAt’ is displayed in response
PUT Request
The HTTP PUT request method is similar to HTTP POST. It is used to update existing data to a server.
A PUT request can pass parameters to the server using "Query Parameters" as well as the “Body Parameters”.
For Example :
Let us assume that you wish to send a PUT request to endpoint https://reqres.in/api/users/2
Also, lets us assume that the data passed during POST request was :
Suppose you select the Content Type as JSON (application/json) while passing the data under “Body Parameters” tab.
When you execute this test, data will be fetched and displayed in the local Executor window.
If you scroll down, you will notice :
Status is displayed for the HTTP PUT request
Updated data is displayed in response
Key ‘updatetdAt’ is displayed in response
DELETE Request
The HTTP DELETE method is used to delete resources on a server.
DELETE request supports "Query Parameters" as well as the “Body Parameters”.
HEAD Request
The HEAD method is identical to GET except that the server MUST NOT return a message-body in the response.
In other words, ifGET /users
returns a list of users, thenHEAD /users
will make the same request but won't get back the list of users.
This method is often used for testing hypertext links for validity, accessibility, and recent modification.This method can be used for obtaining meta information about the entity implied by the request without transferring the entity-body itself.
The meta information contained in the HTTP headers in response to a HEAD request SHOULD be identical to the information sent in response to a GET request.
How to pass data under each tab?
Header Parameters
Header Parameters tab is used to pass data in request header.
For example :
When you execute, the response will be displayed as below.
Query Parameters
Query Parameters tab is used to pass the query string.
The data after the question mark (“?”) in the endpoint is referred as query string.
Example :
There can be multiple query strings in a link separated with an ampersand symbol (“&”)
Example :
These query strings need to be passed as key-value pair under the “Query Parameters” tab.
For example :
The data retrieved will be on the basis of the query string passed under the Query Parameter.
Body Parameters
Body Parameter tab is only used with HTTP requests like POST, PUT, UPDATE and PATCH.
BQ allows it’s users to pass data under Body Parameter in three ways :
form-data
x-www-form-urlencoded
raw
Form-data : It is used while submitting a form or submitting non-encrypted/non-private data.
x-www-form-urlencoded : It is used while submitting login form or submitting encrypted/private data.
raw :
It provides various Content-types like :
Text (text/plain)
JSON (application/json)
Javascript (application/javascript)
XML (application/xml)
Text XML (text/xml)
HTML (text/html)
Extract & Store
Extract and Store tab is used to extract a particular data from the fetched data & store it in a variable.
The tab, when selected, displays four columns :
Source : the source to extract the data from
Available Source Types in BQ : Headers, Response & CookiesSearch Type : type to extract the data
Types available in BQ : Regex, JSONPath & XPathPattern/Query : query to extract the data as per the search type selected
If you select Regex as the Search Type, enter the query in Regex to locate the correct data
If you select JSONPath as the Search Type, enter the query in JSONPath to locate the correct data
If you select XPath as the Search Type, enter the query as XPath to locate the correct dataVariable : variable name to store the extracted value
Let us see an example for each Search Type :
Regex :
If we select Regex as the search type, we will have to enter the query using the regular expressions
For example :
This is the endpoint you wish to retrieve the data from : https://app.bqurious.com
The response received using a simple GET Request is as displayed below
Now, suppose we wish to extract the title of the page.
The query that we would enter would be (\w{1,}-\w{8})
JSONPath :
If we select JSONPath as the search type, we will have to enter the query using JSONPath.
For example :
This is the endpoint from you wish to retrieve the data from : https://reqres.in/api/users?page=2
The response received using a simple GET Request is as displayed below
Now, suppose we wish to extract the first name of the user displayed at the third position on this page.
The query that we would enter would be data[2].first_name
You can always validate the JSONPath query before using, by validating it in JSONPath Online Evaluator.
Please note that indexing in JSONPath starts from 0.
XPath :
If we select XPath as the search type, we will have to enter the query using XPath
Simply mention the XPath of the element you wish to extract and store.
For example :
This is the endpoint you wish to retrieve the data from : https://app.bqurious.com
The response received using a simple GET Request is as displayed below
Now, suppose we wish to extract the username.
The query that we would enter would be //input[@id='username']
Assertions
Assertions tab is used to verify the data.
The tab, when selected, displays five columns :
Action : the type of verification action that needs to be taken on the data
Available actions in BQ : verifyHttpResponse, verifyHttpHeader, verifyHttpStatus, verifyHttpResponseTime and verifyHttpResponseSizeProperty : query to extract the data
Condition : condition that needs to be verified
Available conditions in BQ : EQUALS, IS_EMPTY, IS_NOT_EMPTY, DOES_NOT_EQUAL, CONTAINS, DOES_NOT_CONTAIN, IS_A_NUMBER, EQUALS_NUMBER, LESS_THAN, LESS_THAN_OR_EQUAL, GREATER_THAN, GREATER_THAN_OR_EQUAL, HAS_KEY, HAS_VALUE, IS_NULLData type : data type of the value to be verified
Available data types in BQ : Fixed, Data Table, Stored Variable, Global Variable, Data Table-Encrypted, Unique, Fixed-Encrypted, ExcelValue : value to verify (as per the data type selected)
Here’s a screenshot of how to use the data in Assertions tab :
Info |
---|
For using Global Variable as data type, you will first have to create global variables. |
Info |
---|
You can also pass data as global variable, stored variable & Data Table in the endpoint. |