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 interface (refer to Katalon version 5.4 and above) helps in seemless 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-
- Create a project-
Go to File menu -> New -> Project. Enter project name and select its location. Also, we can optionally provide a project's description.
- On clicking 'OK', we will see a 'Test Explorer' pane on the left hand side.
- Now, right click on "Object Repository" directory icon and click on 'New' -> "Web Service Request"
- 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'.
- On the right hand side, we will see below details for our request.
- Now, we can set the fields with the API specific details like-
- The HTTP method of the API e.g. GET
- The API URL-
- Based on the API, we can similarly set the 'Authorization', 'HTTP Header' and 'HTTP Body' fields.
- 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'.
- 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'.
- On the right pane, we need to add "Web Service Keywords" in order to hit and verify the API response.
- 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 - This keyword is used to check if a string appears in the response of the API. Set the input field as below-
- Once done, the right pane will look like this-
- 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.