Restful API
Purpose
We can run restful api tests through csv files
A single row in csv will have request, response and validation
This allows for writing large number of tests quickly covering the requirements
Implementation
We can set the values in the csv file as follows:

Following example gets authentication token and calls create user api
TestSuite
TestCaseID
RunFlag
Description
InterfaceType
UriPath
ContentType
Method
Option
RequestHeader
TemplateFile
RequestBody
OutputParam
RespCodeExp
ExpectedResponse
TcComments
TsUser
getAdminToken
Y
Retrieve a token from Token GeneratorSQLDB
RESTfulAPI
/auth/local
application/json
Post
{
"identifier": "<@adminUserName>",
"password": "<@adminUserPassword>"
}
user.role.id:<$roles>; jwt:<$accessTokenAdmin>;
user.id:<$userId>
200
{
"user": {
"username": "<@adminUserName>",
"email": "autouser313@gmail.com",
"provider": "local",
"confirmed": true,
"blocked": null
}
}
&&
_VERIFY_JSON_PART_
"user.username":1: hasItems("<@adminUserName>");
"user.email":1:: equalTo("autouser313@gmail.com");
"user.provider":1: isNotEmpty;
"user.role.name":1: contains("Administrator")
&&
_NOT_EMPTY_
TsUser
createUser
Y
create user
RESTfulAPI
/content-manager/explorer/user/?source=users-permissions
application/x-www-form-urlencoded
Post
Authorization: Bearer <@accessTokenAdmin>
{
"username":"zzz_test<@_TIME16>",
"email":"testuser+<@_TIME16>@gmail.com",
"password":"password<@_TIME16>",
"confirmed":true
}
id:<$userId>
201
{
"provider": "local",
"blocked": null
}
&&
_VERIFY_JSON_PART_
"id": isNotEmpty
Column Values
TestSuite: The unique name of the test series
TestCaseID: Unique test id for each test
RunFlag: set 'Y' to run the test. Set 'N' to skip.
Description: Short description of the test.
InterfaceType: RESTfulAPI
URI path append to the base URI defined in apiConfig.property
Full URL path can be used. If value starts with "http", then the url will not be appended to the base URI. eg. http://www.site.com/api/login
ContentType: The content type of the request
Method: type of call made: POST, GET, PUT, DELETE
Option:
RequestHeaders: The header values, separated by ";".
eg. Authorization: Bearer <@accessTokenAdmin>
TemplateFile:
RequestBody: The request body goes here. We can use values set in api config file through the syntax: <@variable>. eg. <@username>, where username="admin" defined in apiConfig.property file.
OutputParams: We can store response values into variables defined here. The variables will then be available for other tests.
Syntax: <$variable>. eg. NAME:1:<$name>. the variable "name" can then be access through syntax <@name> in subsequent tests
RespCodeExp: expected response code value from the api call
ExpectedResponse: Verification of the response goes here. More description in the interface sections.
TcComment: comment for the tests. eg. disable for such and such reasons.
Last updated
Was this helpful?