Data-driven testing approach with Katalon Studio

1. What is Data-driven testing?

Data-driven testing (DDT) is a term used in the testing of computer software to describe testing done using a table of conditions directly as test inputs and verifiable outputs as well as the process where test environment settings and control are not hard-coded.

It is the creation of test scripts to run together with the related data sets in a framework. The framework provides re-usable test logic to reduce maintenance and improve test coverage. Input and result (test criteria) data values can be stored in one or more central data sources or databases, the actual format and organization can be implementation specific. In the simplest form, the tester supplies the inputs from a row in the table and expects the outputs which occur in the same row. The table typically contains values which correspond to boundary or partition input spaces. In the control methodology, test configuration is “read” from a database that can be any of the below data files.

  • Datapools
  • Excel files
  • ADO objects
  • CSV files
  • ODBC sources

Data Driven Testing can be best understood by the following diagram:

data-driven testing

2. Data-driven testing approach with Katalon Studio

Katalon Studio supports data-driven testing which allows users to define data sets and execute test scripts that use these data sets.

This tutorial will provide you a simple example on how to create an automation test case and execute it multiple times using different sets of data.

Given a sample test case whose scenario is as below:

You can use the following steps to automate the above test scenario:

1. Create a new test case and proceed to generate the steps to:

Katalon Demo Pagehttps://d1h3p5fzmizjvp.cloudfront.net/wp-content/uploads/2017/04/11114550/1.-Katalon-demo-300×150.png 300w, https://d1h3p5fzmizjvp.cloudfront.net/wp-content/uploads/2017/04/11… 768w” sizes=”(max-width: 731px) 100vw, 731px” />

You can utilize the Web Record function to quickly generate test steps. Refer to this guide for more details on the Record & Playback feature of Katalon Studio.

2. The generated test case should be similar to the following:

Katalon Test casehttps://d1h3p5fzmizjvp.cloudfront.net/wp-content/uploads/2017/04/11115054/2.-Katalon-test-case-300×152.png 300w, https://d1h3p5fzmizjvp.cloudfront.net/wp-content/uploads/2017/04/11… 768w” sizes=”(max-width: 638px) 100vw, 638px” />

You can see that the input values for username and password are hard-coded as what you typed during recording (in this case it’s admin/abc123). In order to run this script multiple times using different accounts, you need to parameterize these values. Please continue to the next step.

3. Switch to the Variables tab of the test case and create two variables named ‘demo_usn’ and ‘demo_pwd’.

Katalon Variables tab of the test casehttps://d1h3p5fzmizjvp.cloudfront.net/wp-content/uploads/2017/04/11115225/3.-Katalon-Variables-300×144.png 300w, https://d1h3p5fzmizjvp.cloudfront.net/wp-content/uploads/2017/04/11… 768w” sizes=”(max-width: 622px) 100vw, 622px” />

4. Switch back to the Manual view of the test case and set those two variables as inputs for the username/password fields.

Katalon Manual viewhttps://d1h3p5fzmizjvp.cloudfront.net/wp-content/uploads/2017/04/11115341/4.-Katalon-manual-view-300×189.png 300w, https://d1h3p5fzmizjvp.cloudfront.net/wp-content/uploads/2017/04/11… 768w” sizes=”(max-width: 590px) 100vw, 590px” />

Now that you have done the necessary steps to parameterize the required fields for login, proceed to the next steps to prepare data for execution.

5. Create a data file in Katalon to have a dataset containing three login accounts. You can generate data file from sources such as Excel, CSV, Database etc…. Refer to Manage Test Data for more details on how to create test data from different sources. The following example shows the internal data file with three login accounts for http://demoaut.katalon.com (note that only ‘John Doe’ is valid):

Data file in Katalon

https://d1h3p5fzmizjvp.cloudfront.net/wp-content/uploads/2017/04/11115541/5.-Katalon-data-file-300×133.png 300w” sizes=”(max-width: 360px) 100vw, 360px” />

Data-driven tests execution

From here you can apply Data-driven using two methods, either using Test Suites or Loop statement in Test Scripts.

A. Execution from  test suites

6. Next, create a test suite to execute the test case using the defined dataset.

Katalon New test suitehttps://d1h3p5fzmizjvp.cloudfront.net/wp-content/uploads/2017/04/11115921/6.-Katalon-Data-driven-300×170.png 300w, https://d1h3p5fzmizjvp.cloudfront.net/wp-content/uploads/2017/04/11… 768w” sizes=”(max-width: 574px) 100vw, 574px” />

7. Expand the Data Binding section, add the created data file to the Test Data section and proceed to bind the two variables ‘demo_usr’ and ‘demo_pwd’ to the respective columns of the data file. You may refer to Data for test execution for more details about variable binding.

Katalon Test Data sectionhttps://d1h3p5fzmizjvp.cloudfront.net/wp-content/uploads/2017/04/11120012/7.-Katalon-test-data-300×152.png 300w, https://d1h3p5fzmizjvp.cloudfront.net/wp-content/uploads/2017/04/11… 768w” sizes=”(max-width: 600px) 100vw, 600px” />

8. Finally, you can run the test suite, and your login test case will be executed three times using the accounts defined in the test data file.

B. Execute from a test case

6. We can also implement Data-driven tests in a test case. Just create a new test case and switch to Script Mode. To iterate tests with multiple sets of data, we need to use FOR statement and call the test data objects. Copy and paste below code:

import com.kms.katalon.core.testdata.InternalData
InternalData data = findTestData(Demo_Account)
for (def index : (0..data.getRowNumbers()  1)) {
WebUI.openBrowser()
WebUI.navigateToUrl(http://demoaut.katalon.com/profile.php)
WebUI.setText(findTestObject(Page_Login/txt_UserName), data.internallyGetValue(demo_usn, index))
WebUI.setText(findTestObject(Page_Login/txt_Password), data.internallyGetValue(demo_pwd, index))
WebUI.click(findTestObject(Page_Login/btn_Login))
WebUI.verifyElementPresent(findTestObject(Page_CuraHomepage/btn_MakeAppointment), 0)
WebUI.closeBrowser()
}

Where:

  • Import InternalData class from Katalon built in library and define data variable to locate test data table
  • For statement to loop through all row of test data table which indicates how many times the test case will run
  • To get a row value in test data table, use getRowNumbers() method syntax. For example:

Username field: data.internallyGetValue(“demo_usn”, index)

Password field:  data.internallyGetValue(“demo_pwd”, index)\

7. When you done in Scripts view, switch back to Manual view, the test case will look as the following screenshot:

Katalon Scripts viewhttps://d1h3p5fzmizjvp.cloudfront.net/wp-content/uploads/2017/04/11135708/8.-Katalon-Script-view-300×135.png 300w, https://d1h3p5fzmizjvp.cloudfront.net/wp-content/uploads/2017/04/11… 768w” sizes=”(max-width: 588px) 100vw, 588px” />

8. Finally, you can run the test case, and your login test case will be executed three times using the accounts defined in the test data file.

 

Contact: Axl Slash

Leave a Reply

Your email address will not be published. Required fields are marked *