Do you think IIT Guwahati certified course can help you in your career?
No
Introduction
Katalon is an automation testing tool that tests desktop, mobile, and web applications. We have heard about Selenium and Appium which are well-known open-source automation frameworks. So basically, Katalon is developed on top of these frameworks with an additional Integrated Development Environment(IDE) for automation testing of applications.
Through charts, graphs, and reports, Katalon presents test data and execution results that can be visually represented. Test management, planning, and execution are some of its primary characteristics. Jira and other CI/CD tools can be combined with Katalon. By integrating Katalon with Jira, end-to-end quality assurance for Agile and DevOps is accomplished via frictionless project management.
Before we start discussing Data driven testing through Katalon studio, let us first understand what exactly is Data driven testing.
Data Driven Testing
Simply put, data-driven testing is the process of taking a test, parameterizing it, and then running it with varying data.
This enables you to run the same test case with a variety of inputs, increasing coverage from a single test.
Data driven testing, in addition to increasing test coverage, enables the incorporation of both positive and negative test cases into a single test.
Data-driven testing (DDT) is data that is loaded and used outside of your functional tests to extend your automated test cases.
You can run the same test case with as many different inputs as you want, resulting in greater coverage from a single test. This could be an Excel spreadsheet, an XML file, a MySQL database, or something else.
The data is what drives the test, which is why it is referred to as data-driven testing. Data-driven testing can save a development team time and money because it eliminates the need to manually test each piece of data. Instead, testing software such as katalon can automate the testing process.
You can also change the parameters of the test case to reuse it as many times as you want in other situations.
Data-driven testing with RESTful web server requests
We will be using a sample project to understand how to use variables to generate Web Service requests and test cases, then link data files to the corresponding request objects and test cases.
To conduct data-driven testing (DDT) using Web Service Objects, we will use Katalon Studio.
In the particular sample project, to create a new account, we would like to provide the user's information to the server, along with dynamic data like their username, age, password, gender, and avatar. Then the server will have to respond with a user ID. We can utilise the user ID to locate a newly created user.
Creation of Web Service request objects using variables
We require 2 RESTful requests in this case:
For registering a new user in the system, a POST request with variables is used.
To receive a user’s information using an ID, a GET request with variables is used.
POST request creation with variables
A POST request is simply used to send or transmit some data to the server and expect a response corresponding to the request.
With respect to this project, a POST request is sending the user’s name, password, age, gender, and avatar to the server and is expecting a user ID as a response.
We need to follow some steps for creating and configuring the POST request. The following are the steps:
The first step should be to create a Web Service request. This can be done by going to the main menu and selecting File, then New, then Web Service Request.
After this, you need to specify the name of the request and the request type in the New dialog box displayed. The request type should be mentioned as RESTful. Below is an image that shows the New dialog box for creating a new web service request.
2. The second step is to identify and specify the API endpoint. An endpoint for APIs may contain the URL of a server. Each endpoint is a place where APIs can go to get the resources they require to function. Here, we are referring to this API endpoint: https://sample-web-service-aut.herokuapp.com/api/users/json
3. A Variables tab will appear on the screen. For this project, given the input to the server i.e. username, password, age, gender, and avatar variables.
4. Use the ${<variable name>} syntax as a placeholder in any of the available places to call a variable in a Web Service object. For the variables in the HTTP Body tag, we can use the following syntax to identify a variable:
After following these steps, the POST request is generated and sent to the server.
GET request creation with variables
When you issue a GET request, the server locates the information you asked for and provides it back to you. Hence, a GET request does a READ operation.
For this project, a GET request will be used to find a user by its user ID. Using the POST request, we entered the user’s information(i.e. Username, password, age, gender, and avatar), and got back a user ID as a response. Now, by using a GET request, we can receive all the information of the user by simply entering the user ID.
We need to follow certain steps to configure the GET request. The following are the steps:
The first step should be creating a Web Service request. Go to the main menu and choose File > New > Web Service Request. Put a name on the request and choose the RESTful request type in the New dialogue that appears.
2. The second step should be to identify and specify the API endpoint. The API endpoint here is: https://sample-web-service-aut.herokuapp.com/api/users/
3. The ${<variable name>} placeholder should be added to the end of the API endpoint to pass a variable to the GET API.
4. Variables tab will appear on the screen. Give the input as an id variable, like shown below:
After following these steps, a GET request will be created. The next step is creating a test case with the associated Web Service requests.
Creation of a test case with associated Web Service requests
So far, we have created the two RESTful Web Service requests - POST and GET with variables. After this, we need to create a test case to send a POST request to the server for the registration of a new user and receive a user ID in return. Then with the extracted user ID, we can send a GET request to get all the user information, and further verification can be done. For configuring the test case in Katalon, you can refer to this.
To set up the test case, we must perform some steps:
A Script tab will appear. Write the following code for setting up the test case in this tab. A new test case will be created.
// Send a POST request to create a new user
// The response contains the id of the newly created user
post_response = WS.sendRequest(findTestObject('POST a new user,' [('username') : username, ('password') : password, ('gender') : gender, ('age') : age]))
// Extract the id value from the response
user_id = WS.getElementPropertyValue(post_response, 'id')
println("ID of user " + username + ": " + user_id.toString())
// Send a GET request to retrieve user information by id
get_response = WS.sendRequest(findTestObject('GET user by id', ['id' : user_id]))
println("The response is: " + get_response.getResponseText())
// Verify that the returned values match the user information
WS.verifyElementPropertyValue(get_response, 'username', username)
WS.verifyElementPropertyValue(get_response, 'password', password)
2. Navigate to the Variables tab to pass the variables described in the POST request object into the test case. Here, we specify the username, password, gender, age, and avatar variables.
3. The next step is to verify the test case by running it and checking the message that appeared in the Console log.
Frequently Asked Questions
What is meant by RESTful Web Services?
The term "RESTful web services" refers to web services that adhere to the REST (representational state transfer) architecture. The HTTP protocol is used to implement REST(web protocol). The connection between numerous applications created in different programming languages is facilitated by these services, which are light, and offer scalability and maintainability. They connect to the resources on the server which the client needs via the web browser via request headers, request bodies, response bodies, status codes, and other techniques.
What kinds of automation are compatible with Katalon Studio?
Pop-ups, wait-time, and iFrames can all be tested automatically with Katalon Studio. Operating systems like Microsoft Windows, Linux, and macOS all support starting the tool.
Is there any difference between Selenium and Katalon?
Over Katalon studio, Selenium typically moves more quickly. It has to load additional test objects, libraries, etc. because Katalon's scripting language, Groovy, is built on Java and requires that. If the test lasts a long time, the variance in performance and speed would be apparent.
What exactly are the advantages of RESTful APIs?
The most popular APIs in the domain of web services are those that are RESTful. For CRUD operations—creating, reading, updating, and deleting—they use HTTP requests. They are well-liked for being straightforward, scalable, quick, and capable of handling various forms of data.
Conclusion
Hey Ninjas!
In this article, we discussed what Katalon Studio is and its uses. We also briefly discussed how to use variables to generate Web Service requests and test cases, then link data files to the corresponding request objects and test cases. We learned the uses of POST and GET requests in RESTful APIs and how they are used to extract information. After the generation of POST and GET requests, we created a test case.