API Testing With TestProject - KT
API Testing With TestProject - KT
Automation occupies a crucial position in this technology-centric world. Faster and short
releases are in vogue. With this ideology, agile development method has gained a foothold in
the software industry. The way we develop software automation tests in agile has changed
remarkably.
The old practice of having only the GUI tests for automation has been replaced. The problems
in software testing with the GUI tests are several. To enumerate a few:
The tests may fail frequently owing to frequent changes in the UI.
Additional maintenance and refactoring efforts associated with flaky tests
Time consuming test process and slow feedback
More memory required for execution
In a two week aligned sprint, it gets altogether difficult to have a UI ready and test it at the
same time for test coverage results. The API Testing doesn't rely much on the UI, it becomes
much easier to integrate them under the Agile Development, and can be brought in much
earlier at the development stage. The rising trend of API Testing underlines this further.
(https://trends.google.com/trends/explore?date=today%205-y&q=%2Fm%2F0139ygq7 )
With greater adoption to API testing, another interesting trend is the rise of codeless
automation tools. These tools try to address challenges associated with traditional test
automation. They aim to provide solutions to the QA bottlenecks and processes.
Major advantages among them being:
Select ‘Web’ under the ‘Test Type’. (We can as well select mobile/ code for our
tests)
Add the Test details. I have added Test Name as: API Test and added a
description as ‘API Test for Methods Request’
The next in the menu is ‘Add Application under test’. We have to specify the
particular URL where we have to test our APIs. Under this tutorial, I have decided
to use the open API https://reqres.in/ .
After this step, click on blank test as we intend to create our own test suite.
Click on ‘Start Testing’ and we are open to create our tests.
In the Tests section, a list of Tests Steps we have created is displayed. Since we
don’t have any tests steps created under it, a blank page is displayed. Click on
the ‘+’ icon located at left bottom of the left panel as indicated in below diagram.
Lo- behold, we are now ready to create our first ever API tests under this new Test set.
In our previous steps we as clicked on the ‘+’ button a by-default, create step details menu got
enabled. We will proceed writing test details as from next steps:
Click on ‘Element Action’ highlighted above. Select type as ‘Action’ under ‘Element
Action’.
Endpoint https://reqres.in/api/users
HTTP
GET
Method Type
Query
Key: | Value:
Parameters
page: | 2
Body We don’t send body in GET Request
Expected
200
status
Validations
field: response
used
validation type: contains
value : 2
Now let’s add these details into the Test Step Details:
a) Enter the URI as mentioned in above table. Add Query parameter as page = 2 in the
Query field. Add Expected Status = 200 likewise.
b) Scroll down further, now we will add validations.
c) Click on ‘+ add validation’. In ‘Select field’ select ‘response’ and under ‘Select validation
type’ select ‘contains’. Enter value : ‘page’ in the text box as we are validating if we have
got page no. 2 which we were expecting.
The whole request will look likewise:
b) Add an employee to the list of users with some details using POST Request
Click on ‘select element’. Enter ‘HTTP POST Request’ in the search box. Select the
populated result under it of ‘HTTP POST Request’.
The POST Request details we are intending to send are as below:
Endpoint https://reqres.in/api/users
HTTP
Method POST
Type
Query
No parameters are being sent in this request
Paramaters
Body {"name": "morpheus" , "job": "leader" }
Expected
201
status
Validations
field: response | field: response
used
Now let’s quickly add these details into the Test Step Details:
a) Enter the URI as mentioned in above table. Add Expected Status = 201.
b) Scroll down further, now we will add validations.
c) Click on ‘+ add validation’. In ‘Select field’ select ‘response’ and under ‘Select validation
type’ select ‘contains’. Enter value : ‘morpheus’ / ‘leader’ in the text box as we are
validating if we have got page no. 2 which we were expecting.
The whole request will look likewise:
c) Update the added user using a PUT Request:
Click on ‘select element’. Enter ‘HTTP PUT Request’ in the search box. Select the
populated result under it of ‘HTTP PUT Request’.
The PUT Request details we are intending to send are as below.
Endpoint https://reqres.in/api/users/2
HTTP
PUT
Method Type
Query
No parameters are being sent in this request
Paramaters
Body {"name": "morpheus", "job": "zion resident" }
Expected
200
status
Validations
field: response | field: response
used
validation type: contains |validation type: contains
value : morpheus | value: zion resident
Now let’s add these details into the Test Step Details
Enter the URI as mentioned in above table. Add Expected Status = 200.
Scroll down further, now we will add validations.
Click on ‘+ add validation’. In ‘Select field’ select ‘response’ and under ‘Select validation
type’ select ‘contains’. Enter value : ‘morpheus’ / ‘zion resident’ in the text box as we are
validating if we have got page no. 2 which we were expecting.
The whole request will look likewise:
d) And finally delete the created employee using a DELETE Request:
Click on ‘select element’. Enter ‘HTTP DELETE Request’ in the search box. Select the
populated result under it of ‘HTTP DELETE Request’.
The DELETE Request details we are intending to send are as below.
Endpoint https://reqres.in/api/users/2
HTTP
Method DELETE
Type
Query
No parameters are being sent in this request
Paramaters
Body {"name": "morpheus", "job": "zion resident" }
Expected
204
status
Validations No validations in this Request except the status
used 204
Now let’s add these details into the Test Step Details:
Enter the URI as mentioned in above table. Add Expected Status = 204.
The whole request will look likewise:
Once we have created a test suite, we will click on the ‘Save and Exit’ button as our set
of Requests are now ready.
Click on the tab reports, we will get various visualized graphs under Trends and Reports.
We get a detailed view under it. A sample report has been generated as below.
It displays various details such as:
a) Execution time details, agent details, summary over past few weeks, months, days, etc.
b) The test steps with associated execution details such as time, method requests names,
etc.
c) We can download a detailed report in pdf format to share among stakeholders
d) Percentage of tests with step statistics such as passed, failed, aborted, suspended, etc.
This is a very comprehensive report encompassing more than sufficient details of the report.
Summary
In conclusion, so far, we saw the usage of Rest-API Client add-on and created an end to end
scenario for Rest API Tests. We added validations for the status code and response bodies. The
generated test execution report along with test monitoring gave insights into the capabilities of
TestProject(https://testproject.io/) as a potential tool for codeless test automation with its rich
library of add-ons.