Enhanced Variable Binding

Estimated reading time: 3 minutes

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.

Boolean Integer String
TRUE 1 one
FALSE 2 zero
  • 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 will 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.

Quick tips

  • To push customizability further, Katalon now 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, 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, 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.

User Contributed Notes