Your test script is currently using hardcoded data. In automation, hardcoding unique identifiers causes your tests to rely on a specific state of the application’s database. Once that state changes (i.e., the row is inserted), the test environment is altered, causing subsequent runs to fail.
The Solution: Dynamic Data Generation
The industry-standard solution is to ensure your test creates unique data on the fly during every execution. Instead of typing EMP123 or john.doe@company.com, we can append a dynamic timestamp or a random number to the data. This guarantees that every single test run uses a brand-new, unique value.
Custom Keyword Solution
In Katalon Studio, the cleanest way to handle this is by creating a Custom Keyword that generates a unique string (like a timestamp or unique email) that you can pass into your test steps.
Step 1: Create the Custom Keyword
-
In Katalon Studio, go to the Tests Explorer on the left.
-
Right-click on Keywords > New > Package. Name it com.utils.
-
Right-click on the new package > New > Keyword. Name it DataGenerator.
-
Paste the following Groovy code:
Groovy
package com.utils
import com.kms.katalon.core.annotation.Keyword
public class DataGenerator {
/**
* Generates a unique string using the current timestamp.
* Example output: Emp_20260519130542
* @param prefix The prefix for your identifier (e.g., "Emp_")
*/
@Keyword
def static String generateUniqueId(String prefix) {
String timestamp = new Date().format("yyyyMMddHHmmss")
return prefix + timestamp
}
}
Step 2: Use it in your Test Case (Script View)
Now, instead of hardcoding your text in the setText web element modifier, call this keyword at the beginning of your test case.
Groovy
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI
import internal.GlobalVariable as GlobalVariable
// 1. Generate a brand new, unique Employee ID for this specific run
String uniqueEmployeeId = CustomKeywords.'com.utils.DataGenerator.generateUniqueId'("EMP_")
WebUI.openBrowser('')
WebUI.navigateToUrl('http://your-app-url.com/login')
// 2. Use the dynamic variable instead of hardcoded text
WebUI.setText(findTestObject('Object Repository/Page_Dashboard/input_EmployeeID'), uniqueEmployeeId)
WebUI.setText(findTestObject('Object Repository/Page_Dashboard/input_FirstName'), 'John')
WebUI.setText(findTestObject('Object Repository/Page_Dashboard/input_LastName'), 'Doe')
WebUI.click(findTestObject('Object Repository/Page_Dashboard/button_Save'))
// 3. (Optional) Verify the unique ID was successfully added
WebUI.verifyTextPresent(uniqueEmployeeId, false)
WebUI.closeBrowser()
Why this works:
Every time you click Run, Katalon will instantly fetch the current exact second (e.g., EMP_20260519130542). Because time only moves forward, this value will never repeat, ensuring your test passes smoothly on the 2nd, 50th, or 1000th run!