Apologies if this is not in the correct category.
I am noticing that after upgrading to Katalon 7.9, the CustomKeywords javadoc is no longer working in test script view.
Sample method:
Method viewed in Test Case Manual View (shows the javadoc)
Method viewed in Test Case Script View (does not show the javadoc)
This was working until I upgraded from 7.8 to 7.9.
Has anyone had this problem before? If so, how was it fixed?
Quite a few oddities like this appeared in 7.9.0.
Firstly, are you using 7.9.0 or 7.9.1?
If you called your keywords directly, I think they’d work fine - it’s that stringy stuff that’s getting in the way:
import your.package.class.Test
function("s")
By the way, calling a method “function” is confusing - can’t you think of something less obscure? You’ll thank yourself later.
I think @ThanhTo did some work JavaDoc … or maybe it was @duyluong…
To answer your first question, it appears that I am actually using 7.9.1. Sorry about the discrepancy.
The import method you have suggested seems to fix this, so I can use this for now.
By the way, the keywords do work as intended, I am just no longer seeing their definitions when hovering over them without using your workaround (sorry about my poorly named function, just giving the most basic example I could come up with)
Thanks for looking into this.
I’ll move this to bug reports - that’s clearly a loss of functionality.
More about calling the keyword directly…
The only real reason to use custom keywords and @Keyword, is to make them appear in the lists offered by Manual view. If, like me, you live in Script view, you don’t need to write them like that. And if you have a library of utility methods you’d like to use in numerous places, make the methods static and import them statically, too:
public class Myclass {
static void myMethod() {
// do things
}
static void myOtherMethod() {
// do more things
}
...
}
In your TC:
import static mypackage.Myclass.*
// call myMethod ...
myMethod()
// call myOtherMethod ...
myOtherMethod()
Notice, no @Keyword so mymethod will NOT appear in the list offered in Manual view.
Thanks for the tips. By the way, does this only work for .groovy files and not .java files? When I change the Myclass file from the .groovy to the .java extension, the test case will not run (button is enabled, but nothing happens).
There is a way to tell Katalon to read your Java classes - it’s in the project settings somewhere. But I’m not an expert in this area.
@anon46315158 @Brandon_Hein @kazurayam
I’m not aware of any such setting. You can certainly have .java files as part of your project, and reference them from test cases, but from what I understand, your test cases must be .groovy files. (Not saying that it isn’t possible to define them as .java, just that I’ve never seen the setting to make that work).
@james.milos
You can write a Java class in KS. Let me show you an example how to write a Java class and use it in a Test Case.
I wrote a Groovy class in <projectdir>/Keywords/my/GroovyGreeter.groovy:
package my
public class GroovyGreeter {
static sayhelloto(String name) {
return "Hello, ${name}!"
}
}
I wrote a Java class in <projectdir>/Include/scripts/groovy/my/JavaGreeter.java
package my;
public class JavaGreeter {
static String sayhelloto(String name) {
return String.format("Hello, %s", name);
}
}
I wrote a test case script in Test Cases/TC1:
import my.GroovyGreeter
import my.JavaGreeter
println "GroovyGreeter greeted ${GroovyGreeter.sayhelloto('Sapiens')}"
println "JavaGreeter greeted ${JavaGreeter.sayhelloto('Neandertal')}"
When I ran the test case, I got the following output in the console:
2021-02-10 12:12:15.185 DEBUG testcase.TC1 - 1: println(GroovyGreeter greeted $GroovyGreeter.sayhelloto(Sapiens))
GroovyGreeter greeted Hello, Sapiens!
2021-02-10 12:12:15.221 DEBUG testcase.TC1 - 2: println(JavaGreeter greeted $JavaGreeter.sayhelloto(Neandertal))
JavaGreeter greeted Hello, Neandertal
2021-02-10 12:12:15.239 INFO c.k.katalon.core.main.TestCaseExecutor - END Test Cases/TC1
See the following screenshot:
I personally never write Java code in Katalon Studio.
In case I need to develop a fair amount of Java codes for UI testing in KS, I always develop Java codes outside KS. I would design the Java codes completely independent of the com.kms.katalon.** classes, create a jar file, and import the product jar into the Drivers directory of KS project.
Why I do not develop Java in KS?
Firstly, KS is not as good as IntelliJ IDEA as a Java IDE.
Secondly, I think, Groovy language is better fitting for writing scripts for UI testing than Java.
Thirdly, KS forces me a project directory structure which is specifically designed for its problem domain (UI testing by Selenium etc). It is different from the Gradle-conventional directory structure that I like. I feel uncomfortable with KS’s directory structure for Java programming in general. For example, have a look at this path for example:
<projectdir>/Include/scripts/groovy/my/JavaGreeter.java
Here Katalon Studio forces me to locate a *.java file under a directory named groovy. I find this design ugly.