Table of contents
1.
Introduction
2.
What is Katalon
3.
Custom Keywords Refactoring
4.
Import the Custom Keywords Classes by Using Recursion
5.
Mark test's status for a Custom Keyword
6.
Frequently Asked Questions
6.1.
What is Katalon Studio?
6.2.
Why is Katalon Studio used?
6.3.
What is the main advantage of Katalon Studio over others?
6.4.
Can we use Selenium in Katalon?
6.5.
Can we write code in Java?
7.
Conclusion
Last Updated: Mar 27, 2024
Medium

Custom Keywords: Refactoring, Importing the Classes and Mark Tests Status in Katalon

Author Shubham Das
0 upvote
Career growth poll
Do you think IIT Guwahati certified course can help you in your career?

Introduction

We know that Katalon Studio is an automation tool for Android, Windows, macOS, Linux and other platforms. Today, we will look into some more features provided by Katalon Studio. Are you guys excited to learn these?

intro image

But before we dive deep into the topic, let us first learn about what Katalon is.

What is Katalon

katalon

Katalon Studio is a software for automation testing created by Katalon, Inc. It was initially released in January 2015. The software is built on top of the open-source automation frameworks Appium and Selenium with a specialised IDE interface to test desktop, mobile, web and APIs.

Custom Keywords Refactoring

The custom keyword refactoring feature is offered from Katalon Studio version 7.0. So, what are you waiting for? Upgrade your Katalon Studio to the latest version today to enjoy this feature.

Katalon Studio updates the keyword identifier and the new package accordingly when we move a custom keyword from one package to another.


Let’s have a look at an example:

1. In the Katalon project, open the keyword file(WebUICustomKeywords.groovy) or any test case.

example

2. Create a new package(newPackage) in the Keywords folder.

package

3. Drag and drop the WebUICustomKeywords keyword from com.example to the package newly created(newPackage).

4. Re-open the keyword file(WebUICustomKeywords.groovy) or any test case and observe that the package name is automatically renamed from com.example to newPackage

newpackage

Import the Custom Keywords Classes by Using Recursion

How will you call a Custom Keyword within a Custom Keyword that is defined in another class? Let's check it out with a sample implementation of the code.

Keywords/package1/Class1.groovy

package package1

import com.kms.katalon.core.annotation.Keyword

public class Class1 {
	@Keyword
	def bye(String str) {
		return package2.Class2.sayByeTo(str)
	}
}


In the above code, we are trying to call sayByeTo method of Class2 class of the package2.


Keywords/package2/Class2.groovy

package package2

import com.kms.katalon.core.annotation.Keyword

public class Class2 {
	static def sayByeTo(String str) {
		return "Goodbye, ${str}."
	}
}

 

Now, let us write the test Case for our custom keyword.

TestC:

import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUIBIK

def str = CustomKeywords.'package1.Class1.bye'("Shubham")
WebUIBIK.comment(">>> ${str}")

 

A successful run of a test will show you <Passed> in the Job Progress.

progress


Output in Console:

console


Output in Log Viewer:

log

Mark test's status for a Custom Keyword

There is no overall status for a Custom Keyword unless we define our expected result within the Custom Keyword. To generate a status, we will have to follow a couple of functions provided by Katalin Studio.

Name

Description

markError(String message) It marks the keyword which contains an error.
markFailed(String message) It marks the keyword which fails and continues execution.
markPassed(String message) It marks the keyword which is to be passed.

They have a return type of public static void.


Alright! Now we hope you understand the Custom Keywords: Refactoring, importing the classes and marking status tests in Katalon.

Frequently Asked Questions

What is Katalon Studio?

Katalon Studio is an automation tool developed by Katalon, Inc. It works for the web, API, Android, Linux, Windows, and macOS interfaces.

Why is Katalon Studio used?

Katalon Studio is used to create ad reuse automated test scripts for UI without coding.

What is the main advantage of Katalon Studio over others?

Katalon Studio is easy to use and has a broader set of instructions compared to Selenium.

Can we use Selenium in Katalon?

Katalon Studio uses the Selenium engine for automated testing. Katalon uses the Selenium WebDriver framework and hides the complications of dealing with WebDriver from users.

Can we write code in Java?

Yes, we can use Java in Katalon. When writing scripts and custom keywords, we can write them in either Groovy or Java syntax. Groovy is simply a language that extends the Java language.

Conclusion

In this article, we discussed the Custom Keywords: Refactoring, importing the classes and marking status tests in Katalon.

We hope this blog on Custom Keywords: Refactoring, importing the classes and marking status tests in Katalon was helpful. You can also refer to other similar articles.


You may refer to our Guided Path on Code Studios for enhancing your skill set on DSACompetitive ProgrammingSystem Design, etc. Check out essential interview questions, practice our available mock tests, look at the interview bundle for interview preparations, and so much more!

Happy Learning Ninja!

Live masterclass