Statements

Decision-making Statements

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

In Manual view

Open a test case in Manual view, then navigate to Decision-making Statements from command toolbar.

Refer to the following table for the usage of each statement:

Statement Description Screenshot
If This statement requires a boolean condition as input value. Katalon Studio will execute all steps within once the condition is triggered.

Else If Using Else If after If, you can create a combination of conditions where the steps within the first satisfied condition will be executed.
Else This statement serves as the conclusion of the If - Else If - Else structure. The steps within this statement will be executed if all the conditions above it are not triggered.
Switch This statement requires an expression, which is often referred to as the control expression (or control variable), as 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 will have a Break by default which should be positioned at the end of the Case block to mark the end of it.

Default This statement is included automatically within every Switch statement. In situation which no Case value can be matched, the steps within Default will be taken.

In Script view

The Script view of test cases allows you to programmatically define and handle If-ElseIf-Else or Switch-Case structure easily using either Groovy or Java language. Refer to http://groovy-lang.org/semantics.html#_conditional_structures for more details about conditional structure in Groovy.

For example:

Decision-making statement Screenshot
If - Else If - Else

 

Switch - Case  

Looping Statements

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

In Manual view 

Open a test case in Manual view, then navigate to Looping Statements from command toolbar.

Refer to following table for the usage of each statement:

Statement Description Screenshot
For This statement accepts a range, list or array as input value so that Katalon Studio knows how many times to execute all steps within the For structure.

While This statement requires a boolean condition as input value so that Katalon Studio will keep executing all steps within until the condition fails.

In Script view

The Script View of test cases allows you to programmatically define and handle For or While structure easily using either Groovy or Java language. Refer to http://groovy-lang.org/semantics.html#_looping_structures for more details about looping structures in Groovy.

For example:

Looping statement Screenshot
For

While

Branching Statements

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

In Manual view 

Open a test case in Manual view, then navigate to Branching Statements from command toolbar.

Refer to following table for the usage of each statement:

StatementDescriptionScreenshot
BreakKatalon Studio will exit current code block and continue to next code block / test step.

ContinueKatalon Studio will skip the remainder of the current loop and continue with the next iteration of the loop.

ReturnKatalon will exit from the current method/step, and the flow control is returned to where the method/step was invoked.

In Script view

The Script view of test cases allows you to programmatically define and handle Break, Continue & Return easily using either Groovy or Java language. 

For example:

Decision-making statement Screenshot
Break
Continue
Return

Exception handling block

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

In Manual view 

Open a test case in Manual view, then navigate to Exception Handling Statements from command toolbar.

Refer to following table for the usage of each statement:

StatementDescriptionScreenshot
TryThis statement indicates that all steps within will be monitored by exception handlers.

ThrowBefore you can Catch an exception, some code must throw one. Regardless of what throws the exception, it's always involved with the Throw statement
CatchKatalon Studio will execute all steps within when there is any issue occurred during execution of the Try block.
FinallyThis is the last part of the Try-Catch-Finally structure and all steps within this will be executed regardless of any exception.

In Script view

The Script view of test cases allows you to programmatically define and handle exception easily using either Groovy or Java language. Refer to http://groovy-lang.org/semantics.html#_try_catch_finally for more details about exception handling in Groovy.

For example:

Binary Statements

A Binary Statement represents a dual expression consisting of two single expressions (variables, strings, numbers, methods...) and an operator (e.g. +, -, *, <, <=, !, etc.). Refer to Groovy Documents for more details about using operators in Groovy.

In Manual view

  1. Open a test case in Manual view, then navigate to Binary Statement from the command toolbar.

  2. A test step representing a binary statement is added to the test case.

  3. Double-click on the Input cell to edit those required components.

    Binary Statements are normally used to assign either values to test objects

    or test objects to variables to take the next steps.

  4. Save the test case when you're done.

    Once a test step is added as any of the Binary Statement, it will not be allowed to change it into another keyword.

In Script view

The Script view of a test case allows you to programmatically define and handle binary statements easily using either Groovy or Java languages.

For example:

  • To assign a value to a test object

  • To assign a test object to a variable

Method Call Statements

Method Call statement allows you to make calls to other methods provided by the built-in libraries of Katalon Studio.

In Manual view

  1. Open a test case in Manual view, then navigate to Method Call Statement from command toolbar.

  2. A test step representing a method call is added to the test case.

  3. Double-click on the Input cell to edit the called method.

  4. Save the test case when you're done.

    Once a test step is added as Method Call Statement, it will not be allowed to change into another keyword.

In Script view

The Script View of a test case allows you to programmatically define and handle method calls easily using either Groovy or Java language.

For example:

 

Assert Statements

An assert statement contains a boolean expression where this condition must hold true for the test execution to continue. Thus, execution of the assertion causes evaluation of the boolean expression and an error is reported if the expression evaluates as false.

In Manual view

  1. Open a test case in Manual view, then navigate to Assert Statements from command toolbar.

  2. A test step represents assert expression is added to the test case.

  3. Double-click on the Input cell to edit the assertion.

    Once a test step is added as Assert Statement, it will not be allowed to change into another keyword.

In Script view

The Script view of test cases allows you to programmatically define and handle assertions easily using either Groovy or Java language. Refer to http://docs.groovy-lang.org/docs/latest/html/documentation/core-testing-guide.html for more details regarding assertions in Groovy.

For example:

 

Define Method

A method consists of instructions to perform a specific task. Defined methods can be called for being reused later. Refer to Method Call Statements for more details regarding how to call a defined method.

In Manual view

  1. Open a test case in Manual view, then select to add Method from command toolbar.

  2. The Method builder dialog is displayed. Specify the required information for your method as following:

    FieldDescription
    NameThe name of the method.
    Return type

    The object type that this method will return after its execution.

    Setup, Teardown optionsSelect any checkbox to indicate whether it should be a setup() or teardown() method. Refer to SetUp() and TearDown() in Manual view for more details.
    Parameter list

    Any parameter needed to pass into the method.

    By clicking on the Insert button, a row will be appended into the grid. You can then change the type and name of the parameter by double clicking and editing the appropriate cell.

    Click OK after configuring the method details.

  3. A test step representing the recently defined method is added to the test case. You can switch to Script view to define content for the method.

  4. Save the test case when you're done.

    Once a test step is defined as Method, it will not be allowed to change into another keyword.

In Script view

The Script view of a test case allows you to programmatically define and handle methods easily using either Groovy or Java language. Refer to http://groovy-lang.org/structure.html#_methods for details about methods in Groovy.

For example:

Feedback