Skip to main content

Enhanced Variable Binding in Katalon Studio

Note:
  • Starting from version 6.3.0, variable binding can be configured to read test data values as the intended data types. This feature is only applicable for Test data of type Excel and Database.

You can enable this feature to obtain old variable binding behaviors. Old test data continue to be read as string to ensure that we don't break existing test cases.

In this example, we create a test suite and a test case with variables. booleanVar is a test case variable of type Boolean; numberVar a test case variable of type Number; and, stringVar a test case variable of type String.

BooleanIntegerString
TRUE1one
FALSE2zero
  • Create the following custom keyword TestDataKeyword:
public class testdata {

public static void printString(String str) {
println str;
}

public static void printInt(BigDecimal integer) {
println integer;
}

public static void printBoolean(boolean bool) {
println bool;
}

}
  • Use them in the test case Sample Test Case as followed:
TestDataKeyword.takeBooleanAndPrint(booleanVar);
TestDataKeyword.takeNumberAndPrint(numberVar);
TestDataKeyword.takeStringAndPrint(stringVar);

where booleanVar, numberVar, stringVar are test case variables.

Variable binding for Test Data with option bind to test case as string enabled

  • Create a Test Data with the data provided above and the bind to test case as string option enabled.



  • Follow this document to run the test case, and then we have the result as below:



    The test suite should fail when the first keyword function takeBooleanAndPrint does not expect a String; however, due to the enabled bind to test case as string option, the test data values are read as string.

Variable binding for Test Data with option bind to test case as string disabled

  • Create a Sample Test Data with option bind to test case as string disabled.



  • Repeat the same steps as above, and then we have the result as below:



    The test suite should pass because bind to test case as string is disabled. Test data values are read as-is, and all keyword functions receive their expected data types.

Tip:
  • To push customizability further, Katalon Studio supports an annotation called BeforeTestDataBindToTestCase which allows the annotated functions to operate on Test Data variables before they are bound to test cases.
  • Before Katalon 6.3.0, you would have to compile another set of Test Data for each requirement. Increasingly varied requirements would then further complicate Test Data management.
  • Starting from version 6.3.0, you need one raw Test Data file and then define the rules of transformation in different functions using the new annotation. With this feature, deciding how Test Data variables are used occurs at run-time.