@paul.french
Let me tell you by example.
I made 2 Groovy classes:
Keywords/my/CustomKeyword.groovy
package my
import com.kms.katalon.core.annotation.Keyword
public class CustomKeywords {
private static Random random = new Random()
@Keyword
public static int nextRandomInt(int bound) {
return random.nextInt(bound)
}
}
Please note that this class uses @Keyword annotation to a method.
Another code example:
Keywords/my/CutomUtils.groovy
package my
public class CustomUtils {
private static Random random = new Random()
public static int nextRandomInt(int bound) {
return random.nextInt(bound)
}
}
Please note this class has no @Keyword annotation.
The my.CustomKeyword class implements a Keyword as it uses a @Keyword annotation. On the other hand, the my.CustomUtils class does NOT implements a Keyword as it uses no @Keyword annotation.
Then, I made a Test Case script:
Test Cases/TC1
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI
int v1 = CustomKeywords.'my.CustomKeywords.nextRandomInt'(100)
WebUI.comment("v1=" + v1)
import my.CustomUtils
int v2 = CustomUtils.nextRandomInt(100)
WebUI.comment("v2=" + v2)
When I ran the TC1, I got the following output in the console:
2022-10-22 20:47:46.208 INFO k.k.c.m.CustomKeywordDelegatingMetaClass - my.CustomKeywords.nextRandomInt is PASSED
2022-10-22 20:47:46.307 INFO c.k.k.c.keyword.builtin.CommentKeyword - v1=60
2022-10-22 20:47:46.329 INFO c.k.k.c.keyword.builtin.CommentKeyword - v2=99
Both classes worked fine. As you can see, there is no runtime difference between them.
There is only one difference between these 2 classes.
You can open the test case TC1 in Manual mode to edit it. In the Manual mode, you are suppose to operate the GUI widgets to edit the test case. When you are to select a Custom Keyword, you would see the following:
In the dropdown list of available âCustom Keywordsâ, you only find my.CustomeKeywords. You wonât find my.CustomeUtils there.
The reason of this differences is simple: if you write a @Keyword annotation to a custom class, it will be picked up as a Keyword by the Manual mode GUI and will be displayed in the dropdown list. If you donât write @Keyword annotation, then the class is not recognized by the Manual mode GUI, therefore would not appear in the list.
The difference between a custom Keyword and a plain custom class is â with or without @Keyword annotation. Thatâs all. The @Keyword annotation is refered by the Manual mode of Test Case Editor while authoring only. The @Keyword annotation is not significant at runtime.
Obviously, all of built-in Keywords in Katalon Studio is implicitly provided with @Keyword annotations; therefore they are Keywords.
If you use Script mode only, and if you never use Manual mode, then you would never need @Keyword annotations. So I personally rarely use @Keyword as I never use Manual mode.