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.
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)
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.
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 Request”iconnext 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.
Now create Tests
Click on Add drop-down → Select Web Service Keyword(For API tests we use Web Service Keywords)
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.
In the output section, give a variable name. The output of our API is stored in this variable.
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.
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.
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.
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.
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.
Export the Report
We can export the reports to the required formats.From Reports → Right click → Exportas and select the required format.
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