Skip to main content

Decision-making Statements

Note:
  • Once a test step is added as any of the control statements, it is not allowed to change into another keyword.

In manual view

To add decision-making statements in manual view, do as follows:
  1. Open a test case in Manual view. Click on the drop-down icon of the Add button, then choose Decision-making Statements.
    Add decision-making statement
  2. To add a keyword under a statement, select that statement, then click Add. A test step is created under that statement.
    Refer to the following table and example for the usage of each statement:

    If - Else If - Else :

    If-else decision-making statement
    StatementDescription
    IfThis statement requires a boolean condition as an input value. Once the condition is triggered, Katalon Studio starts executing all steps within.
    Else IfUsing Else If after If, you can create a combination of conditions where the steps within the first satisfied condition start being executed.
    ElseThis statement serves as the conclusion of the If - Else If - Else structure. If all the conditions above it are not triggered, test steps within this statement start being executed.

    Switch - Case :

    Switch-case default

    StatementDescription
    SwitchThis statement requires an expression, which is often referred to as the control expression (or control variable), as the input value.
    Case

    The Cases indicate the assumed value for the control expression, with corresponding steps to be executed when a match occurs.

    Each Case Statement has a Break Statement at the end of it by default to mark the end of the statement.

    DefaultThis statement is included automatically within every Switch Statement. If no Case value matches, the steps within Default is taken.

In script view

The Script view of test cases allows you to programmatically define and handle If-ElseIf-Else or Switch-Case structure using Groovy or Java language. For more details about the conditional structure in Groovy, refer to this Groovy documentation: Control structures.

For example:

If - Else If - Else :

if (true) { WebUI.click(findTestObject('Page_CuraAppointment/chk_Medicaid'), FailureHandling.STOP_ON_FAILURE) } else if (true) { WebUI.click(findTestObject('Page_CuraAppointment/chk_Medicare'), FailureHandling.STOP_ON_FAILURE) } else { WebUI.click(findTestObject('Page_CuraAppointment/chk_None'), FailureHandling.STOP_ON_FAILURE) }

Switch - Case :

switch (true) { case true: WebUI.click(findTestObject('Page_CuraAppointment/chk_Medicaid'), FailureHandling.STOP_ON_FAILURE) break case true: WebUI.click(findTestObject('Page_CuraAppointment/chk_Medicare'), FailureHandling.STOP_ON_FAILURE) break default: WebUI.click(findTestObject('Page_CuraAppointment/chk_None'), FailureHandling.STOP_ON_FAILURE) break }

Was this page helpful?