How to write Katalon Studio tests with IntelliJ IDEA and other IDEs


OK, I understand it.



I tried writing JUnit tests for my custom Keywords in Katalon Studio and running the tests with Eclipse. I got a partial success, but encountered a difficulty. Let me report my research and ask for your support.

Successful case

I created a keyword Keywords/junittutorial/Calculator. Please note that this keyword class is a Plain-Old-Java-Object which has no dependency upon the Katalon Studio’s runtime, e.g, the com.kms.katalon.core.configuration.RunConfiguration object)

And I created a JUnit test for it Include/scripts/groovy/junittutorial/CalculatorTest.groovy

I started Eclipse photon, opened the project, and ran the JUnit test. The test ran successfully as expected.

Difficult case

I created another keyword Keywords/my/keywor/MyWebUI. This keyword class tries to instantiate a ChromeDriver. This class has dependency upon Katalon Studio’s runtime.

I created another JUnit test Include/scripts/groovy/my/keyword/MyWebUITest.groovy. This test simply invokes my.keyword.MyWebUI.openBrowser().

When I ran this test in Eclipse, got an Exception with the following statcktrace:

	at com.kms.katalon.core.configuration.RunConfiguration.getDriverExecutionProperties(
	at com.kms.katalon.core.configuration.RunConfiguration.getDriverSystemProperties(
	at com.kms.katalon.core.webui.driver.DriverFactory.isUsingExistingDriver(
	at com.kms.katalon.core.webui.driver.DriverFactory.getExecutedBrowser(
	at com.kms.katalon.core.webui.driver.DriverFactory$ Source)
	at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(
	at my.keyword.MyWebUI.openBrowser(MyWebUI.groovy:22)
	at my.keyword.MyWebUI$ Source)
	at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(
	at my.keyword.MyWebUITest.testOpenBrowser(MyWebUITest.groovy:13)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.lang.reflect.Method.invoke(Unknown Source)
	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(
	at org.junit.internal.runners.statements.InvokeMethod.evaluate(
	at org.junit.runners.ParentRunner.runLeaf(
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(
	at org.junit.runners.ParentRunner$
	at org.junit.runners.ParentRunner$1.schedule(
	at org.junit.runners.ParentRunner.runChildren(
	at org.junit.runners.ParentRunner.access$000(
	at org.junit.runners.ParentRunner$2.evaluate(
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(

Why NullPointerException? It is easily seen. The keyword requires Katalon Studio runtime environment. But my JUnit test does not construct the runtime environment before invoking the keyword. Therefore the keyword can not run anyway.

My thought

Previously I ran my JUnit tests as a TestCase in Katalon Studio, for example see In this way, I could mix codes calling org.junit.* classes and com.kms.katalon.** classes with no problem.


I want to write a custom keyword which has dependency on the Katalon Studio RunConfiguration. I want to do unit-testing for those keywords with JUnit. I want to run the JUnit tests with Eclipse. Then, how can I setup the Katalon runtime environment for each JUnit tests in Eclipse (not in Katalon Studio)?


Do you want to actually interact with browsers in your JUnit tests? My initial thought is that unit tests should be fast, reliable, and isolated so dependencies should be provided as mocks or stubs.


No. Many of the custom keywords I have written so far have no dependency on Katalon Studio runitme environment. I am happy testing them with Eclipse now.

But a few of my custom keywords, as MyWebUI above, is closely related to the Katalon runtime. How to do unit testings for those? My first intension is not to interact with browser, but it is inevitable. Mock or stub — fine, but I do not see how to create a mock of the RunConfiguration.


Can you provide an junit tests which creates a mock of RunConfiguration?


I think Mockito can help here.

Could you please share your tests? I’m on vacation but I’ll take a look and have a sample based on them next week.


Ah, Mockito. I know that of course. However, I could not remeber the name in combination with Katalon Studio ever.


I want to perform JUnit test for a custom keyword which calls the RunConfiguration.getProjectDir(). Of course this method is expected to return the path of a Katalon Studio’s project directory. I made a test and ran it in Eclipse, then I got a failure because RunConfiguration.getProjectDir() returned null. I understood that RunConfiguration.getProjectDir() method requires the runtime environment of a Katalon Studio project.

Taking advice from @devalex88, I thought I should isolate my JUnit test from Katalon Studio runtime environment, wanted to find out a way to implement it. So I tried ExpandoMetaClass of Groovy language, and got a success. Let me tell you what I did.

I made a Groovy file as a JUnit test Include/scripts/groovy/my/keyword/GroovyExpandoMetaClassTest.groovy:

package my.keyword

import static org.hamcrest.CoreMatchers.*
import static org.junit.Assert.*

import org.junit.Before
import org.junit.Test

import com.kms.katalon.core.configuration.RunConfiguration

 * This test demonstrates how to use so called "ExpandoMetaClass" of Groovy language.
 * See for detail.
 * This JUnit test shows that you can dynamically override the static 
 *     getProjectDir() 
 * method of 
 *     com.kms.katalon.core.configuration.RunConfiguration
 * class. 
 * Overriding the Katalon Studio runtime engine by ExpandoMetaClass helps 
 * simplifying JUnit testcases for your custom keywords. This technique enables you 
 * to "mock" the runtime engine with just a few lines of Groovy code.
 * @author kazurayam
class GroovyExpandoMetaClassTest {
    private static final String PATH_X = "/Users/kazurayam/katalon-workspace/projectX"
    void setup() {
        RunConfiguration.metaClass.static.getProjectDir = { -> return PATH_X }

    void testExpandoMetaClass() {
        String s = RunConfiguration.getProjectDir()
        println "[testExpandoMetaClass] " + s
        assertThat(s, is(PATH_X))

I ran this test with Eclipse, and it passed!

With just a few line of Groovy code, I could override the static method (getProjectDir) of Katalon Studio’s core engine class (com.kms.katalon.core.configuration.RunConfiguration) runtime. This case demonstrates the power of Groovy’s metaprogramming. I feel quite comfortable with it.

Now I’ve got to know how to write JUnit tests for my custom Katalon Keywords, how to run them and see the results in Eclipse. I like this approach very much.

The source code is here:

How to Highlight Test object in each and every step

This is awesome @kazurayam. It deserves an article of its own :slight_smile:.



I’m convinced @kazurayam is writing a book - Katalon: The Missing Manual :smiley:


Love this thread. slowly but slowly is about reinventing the wheel :smiley:
Why not simply use IDEA+groovy+Spock?

apply plugin: 'groovy'

group = 'org.spockframework'
version = '1.0-SNAPSHOT'

description = """Spock Framework - Example Project"""

sourceCompatibility = 1.8

repositories {
     maven { url "" }
dependencies {
    compile group: 'org.codehaus.groovy', name: 'groovy-all', version:'2.5.2'
    compile group: 'org.codehaus.groovy.modules.http-builder', name: 'http-builder', version: '0.7.1'
    testCompile group: 'org.spockframework', name: 'spock-core', version:'1.2-groovy-2.5'
    testCompile group: 'com.athaydes', name: 'spock-reports', version:'1.6.1'
    testCompile group: 'org.slf4j', name: 'slf4j-simple', version:'1.7.13'

tasks.withType(Test) {

that’s all you need


Thank you @Ibus that’s definitely another great option. At this moment we haven’t published our Maven-based libraries so if they are required dependencies the setting up will be a little bit tricky.


Well, we are not reinventing the wheel. I want to do unit-testing for custom Keywords with JUnit. In the Katalon Studio GUI it was difficult. Therefore devalex88 proposed alternative way: do it in IDEA or Eclipse. We are reusing the best wheels, aren’t we?


By the way :grin: , I miss “Page Object” in Katalon Studio. I hope I could reinvent the wheel called “Page Object” in Katalon Studio.

Martin Fowler wrote :

However, if you write tests that manipulate the HTML elements directly your tests will be brittle to changes in the UI.

Test Objects in Katalon Studio manipulate HTML elements directly, so my Katalon tests will be brittle to changes in UI.

The “Object Repository” stuffed by “Web Recorder” tool tends to be huge in size where hundreds of duplicating Test Objects are contained. A huge Object Repository is simply hard to maintain. Due to this concern, I would rarely use “Web Recorder” for testing a large-scale Web UI. I have a hope that introducing “Page Object” pattern into Katalon Studio would enable us to reduce the size of “Object Repository”.

I have some web-ui testing projects of mine which use IDE+Groovy+Gradle+WebDriver+Spock+GEB. GEB provides nice implementation of Page Object pattern. I like this tool set.

But I still love Katalon Studio primarily for its easiness for non-programmers (my colleagues at work) to getting started with. They can not get started with the “IDE+Groovy+Gradle+WebDriver+Spock+GEB” tool set ever; it has too much of technical prerequisites — they can not set it up at all.

So I miss “Page Object” pattern in Katalon Studio.


@kazurayam i was just kidding. honestly i love the workarounds proposed.
@devalex88 mhm … i have an idea … not sure if will work.
What if we grab all the jar’s from katalon plugins and bring them into an IDEA project (maven or gradle) ?
In theory if they are in a standard place we should be able to use them …

I have to find some time next week to play with this, in vacation now …



I have given up the idea of testing my custom keywords with JUnit outside Katalon Studio; I mean in Eclipse.

I want to do unit-tests on my custom keyword class com.kazurayam.ksbackyard.ScreenshotDriver. This class interacts with WebDriver to take screenshot of web sites, therefore it requires the Katalon Studio runtime environment. It is impossible to mock the KS runtime environment in Eclipse, so I gave up.

I am going to investigate 2 more options, both will be performed within Katalon Studio GUI:

  1. Use Cucumber (which is built-in Katalon Studio) for testing my custom keyword classes
  2. Develop another custom keyword “runJUnit” and call it in ordinary Katalon Test Cases. The keyword should make it easier to run JUnit tests located in the Includes/scripts/groovy directory. I also want to find some way to view the testing results in concise format.


I started learning Cucumber in Katalon Studio. I read and found such sample code:

import org.junit.runner.RunWith;
import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;
@CucumberOptions(features = "Include/features", glue = "")
public class MyCucumberRunner {}

Well, this code is using org.junit.runner.RunWith. In other words, Cucumber is running on top of JUnit. I have got a clearer view how Cucumber is integrated into Katalon Studio.


I have developed a custom keyword which integrates JUnit in Katalon Studio. See the following post: