Right, data read from data files are read as simple Strings, so this makes sense. (What you are trying to do here is often called “Expression Language,” or EL for short). I don’t know of any built-in EL interpreter for Test Data, but we use a custom implementation:
public static String getELValue(final String value) {
int occurrence = value.indexOf("\${");
if(occurrence >= 0) {
String expression = value.substring(occurrence, value.indexOf("}") + 1);
String function = expression.substring(2, expression.indexOf("("));
String[] arguments = expression.substring(expression.indexOf("(") + 1, expression.indexOf(")")).split(",");
String replacement = "INVALID_FUNCTION";
switch(function) {
case "randomAlphanumeric":
replacement = Functions.randomAlphanumeric(Integer.parseInt(arguments[0]));
break;
case "randomString":
replacement = Functions.randomString(Integer.parseInt(arguments[0]));
break;
case "randomNumber":
replacement = Functions.randomNumber(Integer.parseInt(arguments[0]));
break;
case "randomCharSequence":
replacement = Functions.randomCharSequence(Integer.parseInt(arguments[0]), arguments[1]);
break;
case "todaysDate":
replacement = Functions.todaysDate(Integer.parseInt(arguments[0]));
break;
case "timestamp":
replacement = Functions.timestamp();
break;
}
return getELValue(value.replace(expression, replacement));
}
return value;
}
What this allows you to do is pass in any String, and if the String contains any number of variable handles of the format ${someFunction()}, they will be replaced with the appropriate value (in my case, it’s meant for calling functions, but you could do this with static values or possibly even GlobalVariables). So, for instance, I could have a value in my data file like this:
“The current date is ${todaysDate()}, and the current timestamp is ${timestamp()}”
And if i passed this value to that method, the returned string would be something like:
“The current date is 05/20/2020, and the current timestamp is 134897012341234”
I know this doesn’t directly answer your question, but just food for though that this kind of thing is doable, but it’s not really possible with the built-in Katalon functionality.
tl;dr you cannot put variable handles in data files and expect them to be replaced, they are read simply as String values