2

I am trying to pass some cmd line args from gradle to be used in karate-config.js. Cmd: ./gradlew test -Denv=qa -Dmodule=payments

I looked at https://github.com/intuit/karate#command-line and followed similar steps and put this in build.gradle:

test {
     ...
    systemProperty "karate.env", System.properties.getProperty("env")
    systemProperty "karate.module", System.properties.getProperty("module")
}

Now in karate-config.js, I have code like below:

var environmentvar = karate.env;
var modulevar = karate.module;

environment var (karate.env) variable gets the correct value, but module var (karate.module) always shows as undefined. Any pointers on how to fix this?

Karate 0.9.4 JDK 1.8.0_231

Peter
  • 4,752
  • 2
  • 20
  • 32

2 Answers2

1

Aren't you missing a karate. for e.g.:

System.properties.getProperty("karate.env")
Peter Thomas
  • 54,465
  • 21
  • 84
  • 248
  • That's not the reason. `-Denv` goes in and is mappend in `test` task to `karate.env`. – Peter Jan 21 '20 at 15:42
  • @Peter ah okay. I'm not a gradle expert, so all yours :P – Peter Thomas Jan 21 '20 at 16:12
  • Yes, System.properties.getProperty("karate.env") does not work. Only using System.properties.getProperty("env") works. And System.properties.getProperty("karate.module") or System.properties.getProperty("module") does not work. So wanted to know if there is any other way to pass. – karate_newbie Jan 21 '20 at 17:57
  • @Peter may have other suggestions, but mine is to follow this process: https://github.com/intuit/karate/wiki/How-to-Submit-an-Issue or switch to maven – Peter Thomas Jan 21 '20 at 18:19
1

Just didn't regcognized the important information that accessing karate.env works.

The environment variable karate.env is treated special. Using karate object to access other system properties the same way does not work.

You should read accessing system properties.

Solution: Use karate.properties['prop.name'] to access your module system variable.

In your case:

var environmentvar = karate.env;
var modulevar = karate.properties['module'];
Peter
  • 4,752
  • 2
  • 20
  • 32