Table of contents
1.
Introduction
2.
Assert Statements
2.1.
In Manual View
2.1.1.
Steps
2.2.
In Script View
2.2.1.
Script View as Default Open View 
3.
Define Method
3.1.
In Manual View
3.1.1.
Steps
3.2.
In Script View
3.3.
Example
3.3.1.
Method Declaration
3.3.2.
Method Call
4.
Frequently Asked Questions
4.1.
Is Katalon built on top of Selenium?
4.2.
Does Katalon Studio support desktop application automation testing?
4.3.
What is a Katalon recorder?
5.
Conclusion
Last Updated: Mar 27, 2024

Assert Statements and Define Method in Katalon Studio

Career growth poll
Do you think IIT Guwahati certified course can help you in your career?

Introduction

We know that Katalon Studio is a powerful automation tool. It is mainly intended for the creation and reuse of automated UI test scripts. Katalon Studio also supports automated testing of UI elements such as pop-ups, iFrames, and wait time. But imagine if we need to check for errors in the things we created in Katalon or if we want to bundle up a set of tasks and want them to get done whenever we want to. How will we do that? We can do that by using Assert Statements and Define Methods. Let's find out about them today.

Assert Statements and Define Method in Katalon Studio

Also See, procedure call in compiler design

Assert Statements

We can use an assert statement to write sanity checks in the code. These checks are known as assertions, and we may use them to see if particular assumptions are still true as we write code. An assert statement holds a boolean expression that must be true in order for the test to continue. Thus, when the assertion is executed, the boolean expression is evaluated. It reports an error if the expression evaluates as false. To put it simply, If any of your assertions turn out to be untrue, we can assume that the code contains a flaw.

In Manual View

We can go along with Assert Statements in both manual and Script view. Let us see the Assert Statements procedure in manual view now.

Steps

1. First, we have to open a test case in Katalon Studio. We have to make sure it is opened in manual view. There we have to click on the "Add" button. We will get a drop-down menu. There we will choose the Assert Statements option.

2. For adding a keyword under a statement, we have to select the statement first. Then we will click add, and a test step will be made under the statement.

Screenshot Assert Statement Selection

A test step represents that the assert expression has been added to the test case.

Screenshot Assert Statement 2

3. Now, we will Double-click on the input cell. This will let us edit the method that is called.

Screenshot Assert Statement 3

In Script View

The Script view lets us define and handle assertions programmatically. It is done using groovy or java.

Script View as Default Open View 

Sometimes we are comfortable using the Script View more. Let us have a look at how we can enable Script View as our Default Open View.

1. First, we click on the "Set default view" button present. Once we click, this will pop up the preferences dialog box.

Screenshot Script View 1

2. In the preferences dialog box, we change the default open option from "Manual View" to  "Script View". We then click on "Apply and Close".

Screenshot Script View 2

This will set up the script view as our default open view.

Define Method

A method is a piece of code that only executes when it gets called. We can pass Data, which is also called as parameters, can be passed into a method. Methods, often known as functions, are used to carry out specific activities.

In simple words, a method is just a set of instructions for carrying out a certain task. Defined methods can be called later for use. Let's look at Define Method in Katalon.

In Manual View

We can Define method in two ways. Let us see how it is done in the manual view. 

Steps

1. First, we open a test case in the Manual view. Similar to the previously seen steps, we again have to click on the "Add" button to give us access to the drop-down menu. There we will choose "Method."

Screenshot Define method 1

2. Now, for adding a keyword under the statement, we have to click the statement and click "add" again.

Screenshot Define method 2

Once we do this, the Method builder dialog box will pop up.

Screenshot Define method 3.1

3. Now, we have to give the information needed for our method.

4. Once we have configured the method details, we will click on "OK". As soon as we do this, a test step representing the method that we recently defined gets added to the test case. 

Screenshot Define methods 4

We even have the option to switch to the script view for defining the methods' content. 

Screenshot Script view 3

5. After we are done with the steps, we will just save the test case. 

In Script View

Here again, it is looking similar to the test case. It lets us define and handle the methods programmatically. We can do this using Groovy or Java.

Example

We will have a look at an example:

Method Declaration

Integer CodingNinjasMethod(def coding1. def ninjas2){return coding1 + ninjas2 }

Method Call

CodingNinjasVar = CodingNinjasMethod(varA, varB)

Frequently Asked Questions

Is Katalon built on top of Selenium?

Katalon Studio runs on a Selenium-based engine. In simple words, it is a test automation tool built on top of Selenium. However, many programming skills are not needed to get started with testing in Katalon Studio.

Does Katalon Studio support desktop application automation testing?

Katalon Studio totally supports desktop app automation testing. This support is given for the following platforms: Windows Forms (WinForms), Windows Presentation Foundation (WPF), Universal Windows Platform (UWP), and Classic Windows (Win32).

What is a Katalon recorder?

Katalon Recorder is a record & playback tool which is used for browser automation testing. It is one of the most user-interface-friendly and straightforward Record and Playback extension for Firefox, Edge and Chrome. It is Selenium IDE-compatible and can be called a great Selenium IDE replacement for a daily drive web recorder.

Conclusion

In the blog, we found out about Assert Statements and Define Method in Katalon Studio. We read the simple steps on how we can set them up. We also got to know about manual and script views in them. Learn how to Handle WebDrivers with EventFiringWebDriver in Katalon Studio or about Request History and Draft Request in Katalon. Refer to our courses and explore Coding Ninjas Studio to find more exciting stuff. You can also look into the interview experiences and solve different problems. Look into our Guided paths, test series, libraries and resources to know more.

Thank You

Happy Coding!

Live masterclass