API Testing Using Katalon

Author: Soumya
November 9, 2018
API Testing Using Katalon


As we all know, “Test Automation” is one of the most important and unavoidable factors in the world of testing. With new automation tools invented every day, most of the testers are looking for something that has less coding. Currently, Selenium is one of the most commonly used automation tools. But for Selenium the testers need good programming skills also.

Is there any tool that satisfies the major requirements for a Tester? An efficient Open Source tool with little or no coding when compared to most of the available tools?

The answer –  Katalon Studio, an Open Source Test Automation Tool. When compared to Selenium it is useful for people with little programming knowledge.

Web, Mobile and API testing are possible using Katalon. Here I am giving a basic idea regarding API testing using Katalon.

To start a new API project, launch Katalon

Create the Project

  • File → New → Project → Give a Name

  • Select Project as “Sample JIRA API Tests Project”

We can use the website https://reqres.in/ to get a few sample APIs for our learning.

When the site gets loaded, scroll down to find the sample APIs. By clicking on eachREST-APIin the list, the corresponding request and the response are displayed on top. For now, we will select the simpleAPI – SINGLE USER.

Copy the request for SINGLE USER and append it tohttps://reqres.in/. The url will now change tohttps://reqres.in/api/users/2.Open the same in another tab and check the response.

Katalon blog image 1

Now go to Katalon again. We need to create aWeb Service Requestthere. The best practice is to create aFolderand then create aWeb Service Requestthere to organise them better.

Create Object Repository

Go to Object Repository→Right Click → New → Folder → Give a Name (I gave the name as API 2)

Katalon blog inner image 2

Next Right click on folder API2 → New → Web Service Request → Give a Name (Give a meaningful name here).

As we are doing something related to Users, I have named it as Users.

SelectRequest Typeas RESTful.
In the URL field, give the url we have selected earlier –https://reqres.in/api/users/2. The resultant screen will look like this.

Katalon blog inner image 3

Give the protocol required. Here our url is to obtain the user list. So we can useGETand add parameters if any.Now, click on “Test Requesticonnext to the url field. The result is displayed on the right side with theStatus code, Elapsed timeandSizein bytes.This is how to create a request and test it in Katalon. 

Create Test Cases

Next step is to create aTest Caseand the verification steps, without which we cannot validate the API.

Go to Test Case → Right Click → Folder → Name it.

Right click on Folder → Test Case → Give Name and Tag. Tags will be helpful while searching for the Test Cases.

Katalon blog inner image 4

Now create Tests
Click on Add drop-down → Select Web Service Keyword(For API tests we use Web Service Keywords)

Katalon blog inner image 5

The First Step is to send the request. Start typing “send” and it will display all the items with the entered text. Select “Send Request”. Double click on the null text under Object. Select our required object (Here its User Details under API 2). Click OK.

Katalon blog inner image 6

In the output section, give a variable name. The output of our API is stored in this variable.

Katalon blog inner image 7

Now we can start entering our test criteria and check the status code. From our previous API run, the status code after running the API is 200. So it is easy to verify whether the status code is 200 through our test cases.

Select “Verify Response Status Code”.

In the Input section, double-click. Initially, we need to give the variable name where we have stored our response. So select theValue Typeas “variable” and give the value. Here we are going to give the value “User1” as we had already given the same for the variable earlier. Check the above screenshot.

Next one is the expected Status code. Our status code is 200. So we can give the same there.

Katalon blog inner image 8

Note: If you have any doubt regarding the Keywords, go to the Keywords Browser on left side → Built-in keywords → Web Service Keyword. We can also refer theKatalon Studio Userguides.

If we wish to check for a particular value in the response we got, we can use the “Verify Element Property Value”  keyword.Double click onInput column. As always, the first one is ourResponse object. There we need to give the variable name we had already provided. Next one is the “locator”. If I need to check whether the id value is 2 in our response, we need to give what is the position of this “id”. For this, we can take the help of some JSON pathfinders.

Here I am using the urlhttp://jsonpathfinder.com/ for the same.

Give our response here. Moving on to the result section, click on our required element, in this scenario it is the “id”. It will display the corresponding path on top.

Katalon blog inner image 9

Here the path is “data.id”. Give the same in our test case. And the 3rd one is the value. Give the value “2” there as we need to check whether the id is 2.

Now run the test case and check theLog Viewer. We can see that the test has passed.

Katalon blog inner image 10

Now, let’s run one more time with the id value as 3. This time the test will fail, as in our response, the id value entered is 2.

Run the test and check the Log Viewer. The corresponding test has failed as shown below.

Katalon blog inner image 11

Create Test Suite

Next one is theTest Report. We can’t generate a report just by running theTest Case. For this, we need to create aTest Suite.

Test Suite → Right Click → Create a Folder first to organise better → Right click on Folder → Test Suite → Name it

Click on Add and select the required Test Case and then click OK. Run the Test Suite.
Go toReportsand check. There we can see the report for the executedTest Suite.

Katalon blog inner image 12

Export the Report

We can export the reports to the required formats.From Reports → Right click → Exportas and select the required format.

Katalon blog inner image 13

That’s it. We have tested a sample API and got the report also. Similarly, we can test APIs by making use of the available keywords.

This is just a beginning. There are lots more to be discussed. Keep researching and share your findings friends in the comment section below, as I did.

Reference:How to test API with Katalon Studio byRaghav Pal –https://www.youtube.com/watch?v=Evikp4eQSGs