1

in my karate-config.js, I have set up a default url for an endpoint I use in my tests:

var config = {
    env: env,
    pricingApiUrl: 'http://localhost:8080'
  }

and in my tests that need this endpoint, I assign 'url' to that endpoint * url pricingApiUrl

I know about setting up different environments in the karate-config.js file, but in certain situations I don't know the exact url for the 'pricingApiUrl' until runtime.

So I wanted know if it's possible to set the 'pricingApiUrl' via a commandline flag when I run the tests at the command line.

tomdwp
  • 119
  • 8

2 Answers2

1

Here's one way I found to do it:

1.) in your karate-config.js add the following so that your tests default to using 'http://localhost:8080' (or whatever the default url is for you) or using the value from karate.properties if it exists:

var config = {
    env: env,
    pricingApiUrl: karate.properties['platform.pricing.api.url'] || 'http://localhost:8080'
}

2.) then, run your tests at the command line passing a value for the karate.properties you have defined (karate.properties['platform.pricing.api.url'] in my case):

mvn clean test -Dplatform.pricing.api.url=https://your_heroku_app.herokuapp.com

the 'platform.pricing.api.url' is just an arbitrary descriptive name. You could use a different one.

the url https://your_heroku_app.herokuapp.com is just an example -- put the base url of the api your tests are running against

tomdwp
  • 119
  • 8
0

There's no direct way. Maybe you can contribute code :)

You can check for a system-property and conditionally do stuff. For example:

var config = {
  env: env,
  pricingApiUrl: karate.properties['from.cli'] || 'http://localhost:8080'
}

Other ideas: https://stackoverflow.com/a/52821230/143475

Peter Thomas
  • 54,465
  • 21
  • 84
  • 248