karate framework| I am trying to create multiple karate-config.js file for different env like 'test', 'stage' can somebody help me with an example how I can call env specific config values from different karate config file. I refer this https://github.com/intuit/karate/blob/master/karate-demo/src/test/java/karate-config-contract.js but doesn't clarify what exactly need to do for calling different config.
1 Answers
This part of the karate documentation explains how to check the karate.env
property in your karate-config.js
in order to set configurations and variables depending on your environment.
An other way to archive different configurations per environment is explained here: environment-specific-config
All these approaches solves the issue, to configure different urls for example in your test cases.
Hence, there is no need to call or check for the environment in your feature file in order to get different configuration values. It's done by karate. Just refer to the variables you assigned in karate-config.js
.
You just do something like:
Background:
* url baseUrls.userSystem
Where your karate-config.js
could look like:
function fn() {
if (!env) {
env = 'local';
}
var config = {
baseUrls : {
userSystem : "http://localhost"
}
}
if (env === 'dev') {
config.baseUrls.userSystem = "http://usersystem.default.svc"
}
return config
}
The approach above demonstrate how to use just one karate-config.js
for all enviroments. One file for all.
If you want to create a karate-config-<env>.js
per enviroment, follow the environment-specific-config documentation.
You will find here https://github.com/intuit/karate/tree/master/karate-demo/src/test/java a default karate-config.js
that will be evaluated for every environment. The karate-config-contract.js
will only be evaluated after the karate-config.js
file has been evaluated if and only if the karate.env
property is contract
.
Please read the karate documentation. Peter did a great job to document nearly every little feature karate offers.