How to use external jar functionality directly as custom keyword rather than converting into keyword

Hi All,

In our project, we have created some basic functionality in Java and trying to use that jar in katalon. However, katalon allows customs keyword usage when we cover that functionality with @keyword tag.

We have more than 100 functions and convert that jar functionality to the keyword is tedious. Is there any other way that I can directly use that functionality as customs keyword.

Very likely, yes. I never use @Keyword, all my keyword classes have static methods which I then import statically in my test cases. Maybe that’s enough to get you going…

I’ve never produced a jar though. For that, these guys should be able to help:

@duyluong @ThanhTo @kazurayam

1 Like

You have already created a jar outside Katalon Studio (possibly using Eclipse or Idea etc), right?

Then you can import the jar into Katalon Studio as an external library. Just copy the jar into the <project>/Drivers directory. Refresh KS, or stop&restart KS. Then, the jar will be included in the classpath for your test case script. Your test script can directly call all methods of your classes in the jar. See

You do not have to convert that jar to the custom keywords at all. As Russ wrote, you do not need @Keyword annotation to use your classes in the imported jar files.

Do you want to see example? Have a look at https://github.com/kazurayam/VisualTestingInKatalonStudio/blob/master/Scripts/VT/cleanMaterials/Script1534134775171.groovy
This test case script has lines as

import com.kazurayam.materials.Helpers
...
Helpers.deleteDirectoryContents(...)

The com.kazurayam.materials.Helpers class was developed outside KS, and is contained in a jar which was imported into the Drivers directory of a KS project. Please note that no @Keyword annotation is required.

2 Likes

Thank you kazurayam!
I already imported the jar in katalon, however, not able to see the function names in the custom keyword list. How can I get the custom keyword list from functions from .jar file?

Thank you Russ_Thomas!

I have written code in java and converted in .Jar from eclipse. But not getting that public functions in custom keyword list while writing in Manual mode. How I can achieve that without writing again public functions with @Keyword annotation in Katalon?

@Keyword annotation makes method names visible in the custom keyword list. Without @Keyword annotation, your class#method will not be visible in the list. In the external project you can not code @Keyword annotation (if you write it you will get compilation error). So, you find difficulty to make method names in the custom keyword list.

But if you desperately want to see your keywords in the list, I can show you a trick. Make stubs that liaise the custom keyword list and the class/method implementation contained in the external jar.

Let me assume, you have a class my.external.KeywordX with method doMyMagic() in the external jar, and your Katalon Studio project imported the jar in the Drivers directory.

You make a custom keyword class my.stub.KeywordX in the Keywords directory of your KS project:

package my.stub

import my.external.KeywordX as Ext
import com.kms.katalon.core.annotation.Keyword

class KeywordX {

    @Keyword
    static void doMyMagic() {
        Ext.doMyMagic()
    }
}

You would be able to see a keyword my.stub.Keyword#doMyMagic in the custom keyword list. And calling that keyword in your test case will indirectly call the my.external.Keyword#doMyMagic().

1 Like

Thank you kazurayam!

I am implementing the same… it really help me a lot