How do you manage test data dynamically across multiple environments in Katalon Studio?

Hi everyone,

I am currently working on a project that requires running automated tests across different environments (dev, staging, production). Managing test data manually for each environment is becoming time-consuming & error-prone.

How you all handle dynamic test data management in Katalon Studio:

  • Are you using custom global variables, external files or database connections?
  • Any best practices or tools you recommend for smooth environment switching?
  • How do you avoid hardcoding values inside your test cases?
1 Like

To manage test data dynamically across environments in Katalon Studio effectively:

1. Use Environment-Specific Profiles

Katalon’s Profiles allow seamless switching between environments (dev, staging, prod) without code changes.

  • Define Profiles:
    • Create profiles for each environment (e.g., Dev, Staging, Prod).
    • Set environment-specific variables (e.g., URLs, credentials):
// For Dev profile
baseUrl = "https://dev.example.com"
username = "dev_user"

// For Staging profile
baseUrl = "https://staging.example.com"
username = "staging_user"
  • Access Variables in Tests:
String url = GlobalVariable.baseUrl
WebUI.navigateToUrl(url)
  • Switch Profiles:
    • In the Katalon UI: Use the dropdown in the top-right corner.
    • Via Command Line: Use -profileEnv=Dev when executing tests.

2. Externalize Test Data

Avoid hardcoding by storing data in external files (Excel, CSV, JSON) or databases.

Option 1: Excel/CSV Files

  • Store Data:
testCase,username,password
login_test,user_dev,pass_dev
login_test,user_staging,pass_staging
  • Read Data in Tests:
import static com.kms.katalon.core.testdata.TestDataFactory.findTestData

TestData testData = findTestData("Login_Data")
String username = testData.getValue("username", 1) // Row 1 for dev

Option 2: Databases

  • Fetch Data Dynamically:
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI
import java.sql.*

// Connect to DB (credentials from profiles)
Connection conn = DriverManager.getConnection(GlobalVariable.dbUrl, GlobalVariable.dbUser, GlobalVariable.dbPass)
Statement stmt = conn.createStatement()
ResultSet rs = stmt.executeQuery("SELECT username FROM users WHERE env='dev'")

// Use data in tests
while (rs.next()) {
    WebUI.setText(findTestObject('Login/username_input'), rs.getString("username"))
}

3. Parameterize Tests with Dynamic Data

Generate data on-the-fly for scenarios like unique usernames or emails:

// Generate a unique email
String randomEmail = "user_" + new Date().getTime() + "@example.com"

// Use built-in randomizers
String randomName = org.apache.commons.lang3.RandomStringUtils.randomAlphabetic(8)

4. Use Data-Driven Testing (DDT)

Leverage Katalon’s Data Files to run the same test with multiple datasets:

  1. Create a data file (e.g., users.xlsx) with columns for username and password.
  2. Bind the data file to a test case.
  3. Iterate over rows:
for (int i = 0; i < testData.getRowNumbers(); i++) {
    String username = testData.getValue("username", i)
    String password = testData.getValue("password", i)
    // Execute test steps
}

5. Centralize Configuration with Config.groovy

Create a Config.groovy file to manage environment-specific settings:

public class Config {
    static String getBaseUrl() {
        return GlobalVariable.baseUrl
    }
    
    static String getApiKey() {
        return GlobalVariable.IS_PROD ? "prod_key" : "test_key"
    }
}

6. Version Control & Sensitive Data

  • Store test data files in version control (Git), but exclude sensitive data (e.g., passwords).
  • Use placeholders and replace them at runtime:
// In data files:
username = ${USERNAME}
password = ${PASSWORD}

// Replace via command line (CI/CD):
-g_env.PASSWORD=actual_password

Best Practices

  • Avoid Hardcoding: Always use variables or external data sources.
  • Centralize Data: Use a single source of truth (e.g., Profiles, Excel files).
  • Conditional Execution: Use GlobalVariable.env to conditionally execute steps:
if (GlobalVariable.env == "prod") {
    WebUI.verifyElementPresent(findTestObject("prod_only_element"))
}
  • Leverage APIs for Data Setup: Use WS.sendRequest() to create/cleanup test data via API calls before tests run.

Recommended Tools

  1. Katalon Test Data (Built-in): For simple data parameterization.
  2. External Data Plugins:
  • Excel/CSV Plugins: For large datasets.
  • Database Plugins: For direct DB queries.
  1. Dynamic Test Data Plugins:
  1. CI/CD Integration: Use tools like Jenkins or GitLab CI to inject environment variables:
katalon -projectPath="/project" -browserType="Chrome" -retry=0 -statusDelay=15 -testSuitePath="Test Suites/TS_Regression" -profileEnv=Staging -apiKey=${API_KEY}

By combining Profiles, external data files, and parameterization, we can achieve dynamic test data management that scales across environments while minimizing maintenance

One thing I have noticed when working across multiple environments is that even the most organized setup can get messy fast if data mapping is not centralized or modular. I have been leaning toward using JSON or YAML config files tied to environment specific profiles. It helps keep the test logic clean and makes onboarding new team members a whole lot smoother.

I am still figuring out the best way to sync test data changes when environments are not always in parity (especially when one has legacy data).

How do you handle scenarios where test data needs to evolve or be refreshed regularly across environments without breaking tests or causing inconsistencies?