Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

karate

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...

like image 516
Dunc Avatar asked Oct 10 '17 16:10

Dunc


2 Answers

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

like image 175
Peter Thomas Avatar answered Dec 28 '22 21:12

Peter Thomas


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'.

like image 43
cygne Avatar answered Dec 28 '22 20:12

cygne