I want to get next value by config file which will change by environment.
But I found that when I executed the simualation class, we do not excute karate.config firstly.
So I cannot get the value when define Feeders.
Is there any way to execute karate.config firstly before defining Feeders?
Here is my part of code:
In karate.config define "environment" and "configJsonFile"
var config = {
environment: "dev",
}
config.configJsonFile = karate.readAsString('classpath:com/XXX/config-' + config.environment + '.json')
In feader.feature, get the value from karate.config
Feature: get a list of user account
Scenario: get a list of user account
* json config = karate.get('configJsonFile')
* def userAccounts = config.userAccounts
In MockUtil.class
public class MockUtils {
private static final List<String> userAccounts = (List) Runner.runFeature("classpath:com/XXX/feeder.feature", null, false).get("userAccounts");
private static final AtomicInteger counter = new AtomicInteger();
public static String getNextUserAccount() {
return userAccount = userAccounts.get(counter.getAndIncrement() % userAccounts.size());
}
}
In simulation.scala:
System.err.println(MockUtils.getNextUserToken)
val feeder = Iterator.continually(Map("userAccount" -> MockUtils.getNextUserAccount))
create = scenario("create").feed(feeder).exec(karateFeature("classpath:XXX/XXX.feature"))
setUp(
create.inject(rampUsers(2) during (5 seconds)).protocols(protocol)
)
When I executed this scala file, it will return error which not get value set in karate.config in file "feader.feature".
I tried to print log in karate.config, but no anything shown in console before execting System.err.println(MockUtils.getNextUserToken) in file "simulation.scala".
If anything is not clear, please tell me. Thanks.
Reference: https://github.com/karatelabs/karate/tree/master/karate-gatling#feeders
Expecting:
I can get the data by config file to set feader.
>Solution :
Even in Gatling, Karate should process the karate-config.js before any Scenario. If it is not happening, you may have some problem with your project structure.
Since your question is very complicated and hard to understand, I think you need to follow this process: https://github.com/karatelabs/karate/wiki/How-to-Submit-an-Issue
Note that if you use the Runner.runFeature() API, you have to set the boolean flag to true to run karate-config.js: https://github.com/karatelabs/karate#invoking-feature-files-using-the-java-api