Pass additional parameters to karate-config.js via command line via Maven
Asked Answered
C

3

7

I have additional settings that I need to pass to Karate when running via Maven that will be available in karate-config.js. Currently I can pass in a string using the karate.env property - is it necessary to encode my parameters as a JSON object and pass them in via this one property or can I do something like:

mvn test -DargLine="-Dkarate.env='production' -Dkarate.clientid='1234567890' ...

Such that I can then reference karate.clientid in karate-config.js where I can save it into the returned config object.

I'm sure I'm missing something obvious here...

Composition answered 10/10, 2017 at 16:47 Comment(3)
I found I can do mvn test -D karate.clientId=123 -D karate.baseurl=test.com without the -DargLinePyrenees
@Dunk could you explain more please about what exactly you did for your case. We can't change karate-config.js variables from command line. Example: clientId, baseUrl.. ThanksCaribbean
Peter answer looks good and is there an alternate way like give the parameters from Jenkins and retrieve it in karate config?Bevis
T
5

Yes ! Refer to the documentation for karate.properties['karate.clientid'].

Tompion answered 10/10, 2017 at 16:55 Comment(0)
N
3

You can pass the parameters like this

mvn test -D clientId=123 -D baseurl=test.com

and refer them in the karate-config.js as

karate.properties['clientId'] and karate.properties['baseurl']
Neille answered 24/11, 2021 at 14:59 Comment(0)
C
1

I've found a way, but I didn't use examples. What I've done:

  • In Gradle:

    task api(type:Test) {
       systemProperty "karate.clientId", System.properties.getProperty("karate.clientId")...
     }
    
  • In karate-config.js (in var config):

    clientId: karate.properties['karate.clientId'] || 'xyz'
    
  • In the command line:

    '-Dkarate.clientId=abc'
    

If I don't set the clientId in my command line, the clientId will be 'xyz'.

Caribbean answered 28/1, 2019 at 13:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.