Skip to main content

Variable Binding in Katalon Studio

Note:
  • This feature is only applicable for Excel and Database test data.

You can enable this feature to obtain old variable binding behaviors. Old test data continue to be read as string to ensure that we do not 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 TestDataKeyword custom keyword:
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

  1. Create the following custom keyword:
    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;
    }

    }
  2. Use the keywords in a test case as followed:
    TestDataKeyword.takeBooleanAndPrint(booleanVar);
    TestDataKeyword.takeNumberAndPrint(numberVar);
    TestDataKeyword.takeStringAndPrint(stringVar);
    booleanVar, numberVar, stringVar are test case variables.
  3. Create a test data file with the data below:
    BooleanIntegerString
    TRUE1one
    FALSE2zero

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

You can enable bind to test case as string option so Variable binding can be configured to read test data values as the intended data types.

  • 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:
  • From version 6.3.0, Katalon Studio supports the BeforeTestDataBindToTestCase annotation which allows the annotated functions to operate on Test Data variables before they are bound to test cases. With the annotation, you can define the rules of transformation in different functions in only one Test Data file during runtime.