Sharing keyword file across projects

I’m curious how to best share keyword file(s) between projects, using (for example) Azure DevOps (git) repositories.
Let’s say we have KatalonProject1 in one repository, and KatalonProject2 in another. Presumably we would then have our .groovy keyword file(s) in a separate repository.
How would we reference the keyword file in our projects? Is this even possible? Or would we have to have a copy of the keyword file(s) in each project, but remember not to change the source from the project itself?

Katalon Studio’s document includes the following:

In some cases this would work.

I personally do not use this approach, because their approach works only if the Keyword has no dependencies to any external libraries which is not bundled in Katalon Studio. I quite often use external libraries which are NOT bundled in Katalon Studio — in fact this is the reason why I create my Keywords.

I do the following approach, namely “distribute classes in Jar via Maven repository”

  1. in the Project A, make a jar file which contains the class files of your Keyword
  2. push the jar file into a Maven repository (either public one or private one)
  3. in the Project B, download the jar file from the Maven repository into the Drivers folder of the Project B

There could be a lot of variations how to implement this. How to build the jar? — I use Gradle but you can build it by Maven, Ant etc. Which Maven Repository to host the jar? — the mavenLocal repos on PC, organizational private Maven repository, a Maven repository on GitHub, the Maven Central repository. How to download the jar? — I use Gradle.

Why do I use Maven repository? — I use it in order to resolve External Dependencies required by my custom classes. Resolving external dependencies via Maven Repository is the standard way how all Java programmers in Open-Sourced-Software world share their artifacts. Katalon Studio does not support this. I had a hard time to find out how to use Gradle + Maven Repository for Katalon project. It would not be a practical option for you. So I would not talk about it for now.

1 Like

In my humble opinion Katalon Studio is poorly designed for sharing/reusing custom codes across multiple projects.

My solution for this problem is as follows.

When I develop some Java/Groovy classes that I want to reuse in multiple Katalon Studio project, I always try to separate 2 groups of classes:

  1. classes that are dependent on Katalon API (WebUI.* and WS.* classes).
  2. classes that are independent on Katalon API.

And I always try to make the 1st group classes as thin as possible. I try to implement application logics in the 2nd group classes.

I develop the 2nd group classes out of Katalon Studio; I can use any Java IDE for the 2nd group classes. I would build a jar file that contains the 2nd group classes and I will put the jar in some Maven Repository in my hand. I would show you an example:

In a Katalon project where I require both of groups, I download the jar of 2nd group of classes from the Maven repostory and locate the jar into tha Drivers folder, as the following document tells:

I usually write the 1st group of classes (dependent on WebUI API with @Keyword annotation) in each project by hand. The codes of the 1st group are thin, have no application logics. So I write them once and would rarely update them.

1 Like