I have a karate feature file as below -
Feature: Feature file
@env=dev
Scenario: runs only when karate.env is 'dev'
* print 'karate.env is:', env
@envnot=perf,prod
Scenario: never runs in perf or prod
* print 'karate.env is:', env
And setting env value in karate-config.js as below -
var env = karate.env; // get system property 'karate.env'
karate.log('karate.env system property was:', env);
if (!env) {
env = 'dev';
}
karate.log('karate.env system property was:', env);
But when executing from feature file or runner, it takes karate.env as null unless we run via the command line.
09:15:22.988 [main] INFO com.intuit.karate - karate.env system property was: null
09:15:22.988 [main] INFO com.intuit.karate - karate.env system property was: dev
09:15:23.019 [main] INFO com.intuit.karate - [print] karate.env is: dev
But running from the command line (mvn test "-Dkarate.env=dev") it works -
09:16:55.118 karate.env system property was: dev
09:16:55.133 karate.env system property was: dev
09:16:55.165 [print] karate.env is: dev
Should not scenarios be picked based on the env value instead of "karate.env"?
This is by design. You cannot modify karate.env
once you have kicked off your test suite.
The example you have used for karate-config.js
is just a convenience to set a local variable called env
that can be used within the JS block. It does not live beyond karate-config.js
.