Rest API testing using Katalon Studio
Hello friends, in this tutorial, we are going to learn Restful web service automation using Katalon Studio. Katalon with its new and improved features as well as the interface (refer to Katalon version 5.4 and above) helps in seamless automation of Rest and SOAP web services. If you are new to Katalon Studio, do check our tutorial on Setup and installation of Katalon studio before continuing with this tutorial. Now, let’s see how to do automation testing of Rest APIs using Katalon.
For this demo, we will be using a public dummy REST API – RestApiExample.
Steps for REST API testing using Katalon-
1. Create a project-
Go to File menu -> New -> Project. Enter the project name and select its location. Also, we can optionally provide a project’s description.
2. On clicking ‘OK’, we will see a ‘Test Explorer’ pane on the left hand side.
3. Now, right click on “Object Repository” directory icon and click on ‘New’ -> “Web Service Request”
4. Name the web service request e.g. ‘GetEmployeeRequest’, set the type of API request (e.g. RESTful), provide the API URL (we can also leave it blank in this step) and click ‘OK’.
5. On the right-hand side, we will see the below details for our request.
6. Now, we can set the fields with the API specific details like-
- The HTTP method of the API e.g. GET
- The API URL-
http://dummy.restapiexample.com/api/v1/employees - Based on the API, we can similarly set the ‘Authorization’, ‘HTTP Header’ and ‘HTTP Body’ fields.
7. Now, we can hit the request by clicking the play icon next to the URL field. The response of the same will get displayed in the Response section along with the ‘Status’.
8. Our API request is set now, next we need to create a test case under the ‘Test Cases’ directory. For this, go to ‘Test Cases’ -> ‘New’ -> ‘Test Case’. Name the test case e.g. ‘GetEmployeeDataTest’ and click ‘OK’.
9. On the right pane, we need to add “Web Service Keywords” in order to hit and verify the API response.
10. In this demo, we will add 3 web service keywords-
Send Request – Send request keyword is used for hitting the API that we had set under the ‘Object Repository’ directory. The ‘Object’ field will be the name of the API i.e. ‘GetEmployeeDataTest’. We also, need to save the output to a variable by setting the ‘Output’ field with a variable name. The same variable will be used in subsequent keywords.
Verify Response Status Code – This keyword is used for verifying the response status on hitting the API. Set the input field as below-
Contains String – WE can use this keyword to check if a string appears in the response of the API. Set the input field as below-
11. Once done, the right pane will look like this-
12. Now, we just need to hit the play icon to run the individual test case. Alternatively, we can also add multiple test cases to a ‘Test Suite’ and run the whole test suite in one go.
This concludes our tutorial on API testing using Katalon Studio. Do check our other tutorials on Katalon Studio to further enhance the script.