Skip to content
Advertisement

Karate ReferenceError: package is not defined

I’m using java codes in karate feature file, refering github demo:

Background:
* url demoBaseUrl
* def JavaDemo = Java.type('com.intuit.karate.demo.util.JavaDemo')

I noticed that the feature file is in src/test/java, which defined as classpath in pom.xml. Meanwhile the util class is in src/main/java.

In my project I use similar structure

enter image description here

Following code is in the feature file with Class Reference:

    * def XMLValidator = Java.type(base.utility.XMLValidator)
    * def validator = new XMLValidator()

But I got an exception below:

org.graalvm.polyglot.PolyglotException: ReferenceError: "base" is not defined

Is it a classpath problem?

Advertisement

Answer

Aren’t you missing the quotes (for a string argument to Java.type()

* def XMLValidator = Java.type('base.utility.XMLValidator')
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement