Introduction to Custom Keywords


#1

This is a companion discussion topic for the original entry at https://docs.katalon.com/katalon-studio/docs/introduction-to-custom-keywords.html

#2

If you want to use Custom Keywords in a “Step Definition” .groovy file, what “import” package do you use?


#3

I have run into the same problem. Have you found a solution for this?


#4

Say your custom package is in Keywords/my.keywords/myCustom.groovy and that the class is called myCustom and that there is a method named 'myMethod()` inside the class.

In which case you would add:
import my.keywords.myCustom()

To use myMethod() you would then need:

myCustom x = new myCustom()
x.myMethod()

I tend to declare the class at the top of my scripts as a static, then you can use it throughout the script as an alias. Eg.

private myCustom mc = new myCustom
...
def blahh () {
   ...
   mc.myMethod()
   ...
}
...

I hope that helps