简体   繁体   中英

How do I configure and use/switch between configuration environments using Karate

I'm trying to configure different testing targets via karate-config-<env>.js files located in the same directory.

When I try to execute the tests against the different target-systems:

mvn test -Dkarate.env=int02 (tried: -DargLine="-Dkarate.env=int02")

the karate-config-int02.js file is not executed and the test execution gets stuck somewhere.

I've read the documentation , but for now I found no working example.

I am working with karate 0.9.4 on macOS with Java 1.8 in a maven 3.6.0 example-project for a prof of concept.

Extending the pom file, as shown below, was also not working:

<properties> 
<karate.env>int02</karate.env>
</properties>

I though that via the -Dkarate.env=int02 I could ensure that the karate-config-int02.js would be used to configure the instance specific properties I need.

I do have a line in both karate-config files like:

karate.log('karate-config|karate-config-int02 is called')

but I always see:

karate-config is called

The simplest way and how 90% of projects do it is with just the one karate-config.js and then some if else JS logic as per the docs. Maybe you can stick to that.

var env = karate.env || 'dev';
var config = { someUrlBase: 'https://localhost:8080/' };
if (env == 'stage') {
  // over-ride only those that need to be
  config.someUrlBase = 'https://stage-host/v1/auth';
} else if (env == 'e2e') {
  config.someUrlBase = 'https://e2e-host/v1/auth';
}
return config;

Else please follow this process so we can figure out what could be wrong: https://github.com/intuit/karate/wiki/How-to-Submit-an-Issue

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM