Skip to main content

Test case variables

Test case variables are variables defined in a test case. In Katalon Studio, test case variables are defined in the Variables tab.

Instead of running test case with hard-coded values, you can create test case variables and dynamically run the test case with different inputs.

Add test case variables

In this example, we want to pass variables to the following statement:

println "${employee} - ${department}"

Follow the steps how to add a new test case variable using the statement above:

  1. Navigate to Tests Explorer and open a test case from the Test Cases folder.

  2. In the Test Case Editor, navigate and click the Variables tab to view the test case variables.

  3. To add variable using grid view, click Add.

  4. A new row is automatically added to the variable list.

    Enter your variables and values.

The result after running the test case with variables will be the same with hard-coded values:

Add masked test case variables

Follow the steps how to add a new test case variable using the statement above:

  1. Navigate to Tests Explorer and open a test case from the Test Cases folder.

  2. In the Test Case Editor, navigate and click the Variables tab to view the test case variables.

  3. To add variable using grid view, click Add and enter your variables and values.

  4. Navigate the test variable row to the right and check the box under the Masked column.

    Enter your variables and values.

    Add masked variable

The result after running the test case with masked variables will be the same with hard-coded values, except that the masked variable is hidden in asterisks.

Test run result with masked variable

In the example below, the masked variable is shown in the following:

  • Log Viewer:

    Masked variable in Log Viewer
  • Report (HTML):

    Masked variable in HTML Report

View and declare variables in Script mode

Switch to Variable (Script Mode) tab, Katalon Studio will display a Script Editor with XML format.

For example:

Call a test case with variables

The following is an example of dynamically calling a test case with a set of values.

  1. Open a test case in Manual view, then click Add and select option Call Test Case.

  2. The Test Case Browser dialog which shows all existing test cases within the project will be displayed. Select the test case to be called and click OK.

    In the following example, we call the "Test Case with variables" test case.

  3. A Call Test Case step will be added with the selected test case above as its target.

    call test case with variables

The result after running the test case will be displayed as below:

### Call Test Case in Script mode

In Script tab, the callTestCase method allows users to make a call to another test case.

Refer to the following example:

WebUI.callTestCase(findTestCase('Data-driven Testing/Test Case with variables'), [('employee') : 'John', ('department') : 'Marketing', ('position') : 'Manager'], FailureHandling.STOP_ON_FAILURE)
Was this page helpful?