How to create utility class in katalon?

Hi,
i`ve been using soapui for long time and i know how to create utility class with their library.
I would like to do the same with katalon.

Say for example:
Util.groovy:

public class Util {
//i don`t know what librairies i should use here…
}
public static void test_person(){
def myFile = new File(“C:/temp/myfile.json”);
JsonSlurper jsonSlurper = new JsonSlurper();
def parseJson = jsonSlurpe.parse(myFile )
String json = JsonOutput.toJson(parseJson)
def prettyJson = JsonOutput.prettyPrint(json)
assert test_person = ("person_expected: "+parseJson.person[0]) == “Clopin”
assert test_lname = ("lname_expected: "+parseJson.person[0]) == “Clopan”
assert test_adr = ("adr_expected: "+parseJson.person[0]) == “Clopin street”
assert test_city = ("city_expected: "+parseJson.person[0]) == “Clampin ville”
}

test.groovy
in this class i want to call only
assert test_person = ("person_expected: "+parseJson.person[0]) == “Clopin”
assert test_adr = ("adr_expected: "+parseJson.person[0]) == “Clopin street”

is it correct to use like:

Util.test_person().assert test_person = ("person_expected: "+parseJson.person[0]) == “Clopin”

Thank you for any help and suggestions.

See if this helps:

Thank you, it works for me.

1 Like

Select File > New > Package from the main menu. The New Keyword Package dialog is displayed. Enter a name for your package and click OK.

A new package is created under the Keywords folder in Test Explorer accordingly.

Create a Custom Keyword
Select File > New > Keyword from the main menu. The New Keyword dialog is displayed. Enter a name for your keyword and specify a package for the keyword. Click OK.

By default, a class name cannot start with a number, contain spaces, or have special characters. The Java naming convention suggests creating a class name using a noun or a noun phrase, with the first letter of each word capitalized, to better manage the project.

You can generate sample custom keywords for Web, Mobile, and API Testing. Refer to this guide.

A new keyword is created under the specified package accordingly.

Enter the following code snippet in your class to define a custom keyword:

@Keyword (keywordObject = “<category_name>”)
def keywordName(parameters…) {
// enter your code here
// you can use either Groovy or Java
}