Table of Contents
Enroll in Selenium Training

Katalon Studio provides the ability to dictate the logical flow of execution by supporting control statements such as If/Else, for/while or Try/Catch… which are very common concepts in programming language. This tutorial will explain in details how to use control statements in Katalon Studio along with examples for each case.

The following control statements are supported in Katalon Studio:

  • Decision-making statements (https://goo.gl/BDn5JY)
  • Looping statements (https://goo.gl/a5YHHS)
  • Branching statements (https://goo.gl/cMX373)
  • Exception handling block (https://goo.gl/XFYhGt)

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

Decision-making statements

In Manual View

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

navigate to Decision-making Statements from command toolbar

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

Statement Description
If This statement requires a boolean condition as input value. Katalon Studio will execute all the 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.

you can create a combination of conditions

Statement Description
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 the situation in which noCase value can be matched, the steps within Default will be taken.

Common Condition and Control statements with Katalon Studio

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 conditional structure (http://groovy-lang.org/semantics.html#_conditional_structures) in Groovy for more details.

For example:

Decision-making statement Screenshot
If - Else If - Else Here is an example on how to use if-else if-else in Scripting View where the Click action will be carried out based on the condition ! how to use if-else if-else in Scripting View
Switch - Case Here is an example on how to use switch-case in Scripting View where the value B will be calculated based on the passing value of variable A ! how to use switch-case in Scripting View

Looping statements

In Manual View

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

Looping Statements in Manual view

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

Statement Description
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.

statement in manual view

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

while statement in manual view

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 looping structures (http://groovy-lang.org/semantics.html#_looping_structures) in Groovy for more details.

For example:

Looping statement Screenshot
For Here is an example on how to use For in Scripting View where the acceptAlert keyword will be executed 10 timeshow to use For in Scripting View
While Here is an example on how to use For in Scripting View where the value of varA is true how to use For in Scripting View

Branching statements

In Manual View

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

Branching Statements in manual view

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

Statement Description
Break Katalon Studio will exit current code block and continue to next code block/test step.

branching statement in manual view

Statement Description
Continue Katalon Studio will skip the remainder of the current loop and continue with the next iteration of the loop.

Continue statement in manual view

Statement Description
Return Katalon will exit from the current method/step, and the flow control is returned to where the method/step was invoked.

return statement in manual view

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 Here is an example on how to use Break in Scripting View in order to exit current code block and move to next code block. how to use Break in Scripting View
Continue Here is an example on how to use Continue in Scripting View in order to skip the remainder of the current loop and continue with the next iteration of the loop.Common Conditionhow to use Continue in Scripting View
Return Here is an example on how to use Return in Scripting View in order to exit from the current method, and the flow control is returned to where the method was invoked.how to use Return in Scripting View.png

Exception handling block

In Manual View

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

Exception Handling Statements from command toolbar

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

Statement Description
Try This statement indicates that all steps within will be monitored by exception handlers.
Throw Before you can Catch an exception, some code must throw one. Regardless of what throws the exception, it's always involved with the Throw statement
Catch Katalon Studio will execute all steps within when there is any issue occurred during execution of the Try block.
Finally This is the last part of the Try-Catch-Finally structure and all steps within this will be executed regardless of any exception.

manual view statements

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 this guide for more details about exception handling in Groovy.

For example:

the Script view of test cases

Handle Drag and Drop testing for web applications with Katalon Studio
Handle Drag and Drop testing for web applications with Katalon Studio
Previous Article
Database Testing using Katalon Studio
Database Testing using Katalon Studio
Next Article

Similar Articles

Feedback