API Testing With TestProject - KT

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 14

End to End Rest API Testing with TestProject

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:

 Provide opportunity to testers without coding skills to be involved in automation


process.
 As companies try to shorten release cycles, both testers and developers benefit from
these tools
 Makes the process of writing tests faster and reduces maintenance associated with
them
 Focus for testers gets re-aligned to business knowledge and not worrying much about
learning curve of coding skills
TestProject(https://testproject.io/) is one such codeless automation tool. This post will explain
the usage of TestProject in creating first End to End Rest API Test Suite from scratch. We will be
using an add-on (https://github.com/testproject-io/addons/tree/master/restful-api-client ) to send
HTTP/S requests for GET, PUT, POST and DELETE methods. The installation details have been
documented here (https://docs.testproject.io/testproject-addons/installing-community-addons-from-
the-store). Please go through the small document and we will jump in right away to write our
end to end Rest API Test Suite.
To begin with, we are going to follow these steps:
1) Installation and set of TestProject
2) Create a sample API test project
3) Add API Tests under API Test project
4) Trigger the tests
5) Observe the results
6) Further enhancements

1) Installation and setup of TestProject


 The installation and setup of TestProject has been documented here.
(https://docs.testproject.io/getting-started/installation-and-setup). Please follow
these steps.

2) Create a sample API Test Project


 Navigate to the Home page. Click on the ‘Add a new project’ button located in
the central section.
 Add name and description to the project. Let’s call the project ‘API Tests with
Test Project’ for now. Click on the ‘Create’ button.
 Shortly, you will automatically be navigated to the ‘Tests’ sub menu page.
 Click on Add New Test button located below the tool-bar.

 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.

3) Add API Tests under API Test project


For this end to end API Tests, we will use a publicly hosted API (https://reqres.in).
Our scenario will involve following steps:
a) Get the employees available on page no.2 using GET Request
b) Add an employee to the list of users with some details using POST Request
c) Update the added user using a PUT Request
d) And finally delete the created employee using a DELETE Request
While doing so, we are adding validations on the status code as well as the responses being
added. I have enlisted it below each method request in a tabular format.

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’.

a) Get the employees available on page no.2 using GET Request


 Click on ‘select element’ highlighted above. Enter ‘HTTP GET Request’ in the search box.
Select the populated result under it of ‘HTTP GET Request’.
 The GET Request details we are intending to send are as below:

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

  validation type: contains |validation type: contains


  value : morpheus | value: leader

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.

4) Trigger the Tests


We will now trigger the tests. Navigate to the ‘Tests’ tab. Click on the ‘Play’ button icon. This
will trigger the tests.
Select the Agent, select browser under the agent. Enter the application URL and click on ‘RUN’
button.

5) Observe the results


After we run the tests, we see this status of execution as below under the monitoring tab:

 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.

You might also like