Using import statement for Custom Keyword

Hi,

I have created a custom keyword in a package

“utils.helper.webUIHelper”

I am trying to call the keyword as follows:

import utils.helper.webUIHelper as webUIHelper

webUIHelper.‘waitAndVerifyElementVisible’(‘cccom’)

However keep receiving an error about the parameter being passed is [cccom] instead of Java.lang.String.

Is there any way of calling the keyword this way as opposed to always using CustomKeywords.‘’ ?

The code which calls your custom keyword should be:

def result = CustomKeywords.'utils.helper.webUIHelper.waitAndVerifyElementVisible'('cccom')

@Katalon team

import utils.helper.webUIHelper as webUIHelper
webUIHelper.'waitAndVerifyElementVisible'('cccom')

This is what people usually expect, I think. But the Katalon’s design how to call custom keyword is different. Users get confused here.

I am afraid that the official document “Define custom keywords” is not clear enough how the caller code should look like. The document should describe the syntax more carefully with enough examples in the Script view.

@Katalon team

I hope Katalon to publish a description why the way to call custom keywords is designed as such. I would like to know why the usual syntax were abandoned. Any reason is there for dynamic compilation and class loading?

1 Like

Hey. Is there any update on this? Importing custom Keywords as a preferred name should be a thing. There should at least be some explication as to why we have to call the whole string “CustomKeywords.‘webUtility.canvasUtil.clickCenterOfCanvas’(canvas)” is very heavy when used multiple times in the same script (as I have to click on my canvas multiple times).

This style (CustomKeywords.'XXXX.mmm'()) is designed for the sake of “Manual mode”. You want to create a Test Case using “Manual mode” and pickup your clickCenterOfCanvas keyword from GUI menu by WYSIWYG operation, and you serialized your test case; then the script will be generated in this style.

The @Keyword annotation tells Katalon Studio GUI which class/method should be listed in the GUI menu of Manual mode as an avaliable “Keyword”. This is the only reason why @Keyword annotation is there.

If you do not use the “Manual” mode at all, then the @Keyword annotation and CustomKeyword class are useless for you. You do not need to annotate your custom method with @Keyword at all. You do not have to use CustomeKeywords."xxxxxx.mmmm"() syntax.

Katalon’s official documentation does not (and will never) mention this point. I can empathize with them; they would want to promote “Manual mode”, because the Manual mode is a competitive edge of their product, though you may not need it.


If you don’t need Manual mode and write your Test Cases using Script mode, alternatives are possible. You can write your Test Case script in usual Java coding style as follows:

import my.webutility.CanvasUtil
...
CanvasUtil.clickCenterOfCanvas(canvas)

or

import static my.webutility.CanvasUtil.clickCenterOfCanvas
...
clickCenterOfCanvas(canvas)

Nothing tricky.

1 Like

Ahhh I see! This absolutely should be well explained in the Custom Keywords documentation, as it is only used by people who already use / bought the product. I understand better now their vision of Keywords, it makes sense. You’re right, it’s really simple to fix the small issue, yet so hard to find answers about it. Thanks a lot!