Data-Driven Testing best practices
This document explains the best practices when working with data-driven testing.
- Katalon Studio 7.0+ (Free or Enterprise edition)
- A Test Data sheet: Excel/CSV with user credentials
- Captured Test Objects: Login form elements (username, password, login button).
Data-driven testing works best in testing scenarios involving multiple data sources, such as various logins with different user credentials. Testing approach becomes simple: Design a single, dataβdriven login test case that reads user credentials from an external data source (e.g., Excel or CSV), and execute it with multiple data rows representing valid users, invalid credentials, and locked accounts.
By parameterizing the username, password, and expected outcome (SUCCESS, FAILURE, ACCOUNT_LOCKED), you avoid creating 5+ separate test cases, improve coverage of positive and negative scenarios, and make it easy to add or update user types simply by editing the test data file instead of changing test logic.
Get Startedβ
Assume that there's a data structure as below:
| username | password | expectedResult |
|---|---|---|
| john@test.com | Pass123! | SUCCESS |
| jane@test.com | Pass456! | SUCCESS |
| invalid@test | WrongPass | FAILURE |
| locked@test | Pass789! | ACCOUNT_LOCKED |
Step 1: Create a Test Data File from Test Data sheetβ
- Go to File > New > Test Data
-
Name:
LoginCredentials -
Select Excel File (or CSV)
-
Browse and select your Excel file
-
Check "Use first row as header"
-
Click OK and save
Step 2: Create Test Case with Variablesβ
-
File > New > Test Case β Name:
Login_DDT -
Click Variables tab
-
Add variables:
| Name | Type | Default |
|---|---|---|
| username | String | john@test.com |
| password | String | Pass123! |
| expectedResult | String | SUCCESS |
Step 3: Write Test Scriptβ
This example script below navigates to the login site, input credentials, and validate if the outcome is as described in the test data sheet.
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI
// Navigate to login page
WebUI.navigateToUrl('https://example.com/login')
// Fill login form with variables
WebUI.setText(findTestObject('Object Repository/Username_Input'), username)
WebUI.setText(findTestObject('Object Repository/Password_Input'), password)
WebUI.click(findTestObject('Object Repository/Login_Button'))
// Verify result based on expected outcome
if (expectedResult == 'SUCCESS') {
WebUI.verifyElementPresent(findTestObject('Object Repository/Dashboard_Page'), 5)
println("β Login successful for: ${username}")
} else if (expectedResult == 'FAILURE') {
WebUI.verifyElementPresent(findTestObject('Object Repository/ErrorMessage'), 5)
println("β Error handling verified for: ${username}")
} else if (expectedResult == 'ACCOUNT_LOCKED') {
WebUI.verifyElementPresent(findTestObject('Object Repository/LockedMessage'), 5)
println("β Account locked message verified for: ${username}")
}
Step 4: Configure Data Bindingβ
-
In test case, click Data Binding tab
-
Click Add in Test Data section
-
Select
LoginCredentialsfile -
In Variable Binding section:
-
Map
usernameβ Column:username -
Map
passwordβ Column:password -
Map
expectedResultβ Column:expectedResult
-
- Click Map All (if column names match variable names)
Step 5: Execute Testβ
-
Click Run button
-
Katalon executes test case once for each data row (4 iterations)
-
View results in Log Viewer:
Test Cases/Login_DDT (2.5s)
βββ Iteration 1 - username=john@test.com, password=Pass123! (0.6s) - PASSED
βββ Iteration 2 - username=jane@test.com, password=Pass456! (0.6s) - PASSED
βββ Iteration 3 - username=invalid@test, password=WrongPass (0.7s) - PASSED
βββ Iteration 4 - username=locked@test, password=Pass789! (0.6s) - PASSED
Step 6: Error Handlingβ
// Validate data before execution
if (username == null || username.isEmpty()) {
throw new Exception("Username cannot be empty")
}
if (!(username =~ /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/)) {
throw new Exception("Invalid email format: ${username}")
}
// Handle missing password
String pwd = (password == null || password.isEmpty())
? "DefaultPass123"
: password println("β Data validation passed for: ${username}")
Common Pitfalls to Avoidβ
When designing variables and referencing external data files for DDT, adherence to clean code naming conventions is essential:
-
Global Variables: When declaring global variables, use the Uppercase string convention.
-
Local/Test Cases Variables: Use CamelCase when declaring local or test case variables.
-
Variable Naming: Avoid using variable names that have no meaning or using keywords. Instead, ensure that you add appropriate comments or descriptions to define the variable's purpose.
-
Data File References: Ensure that you select the "Use relative path" option in the file information settings when referencing data files.
Scaling Recommendationsβ
-
Organize data files by feature (Authentication/, Checkout/, etc.)
-
Use database data sources for large datasets (100+ rows)
-
Implement CI/CD integration to run DDT automatically
-
Use Katalon TestOps for centralized reporting