Search code examples
cucumberkarategherkincucumber-junit

How to reset env for cucumber-reports through commands in karate


I have one runner file in karate to generate cucumber reports

public void genrateFinalReport() {
        System.setProperty("karate.env", "pre_production"); // ensure reset if other tests (e.g. mock) had set env in CI
        Results results = Runner.parallel(getClass(), 1);
        generateReport(results.getReportDir());
        assertTrue(results.getErrorMessages(), results.getFailCount() == 0);
    }

in this i have set enviroment to pre_production.

I want to change or modify environment through the command line.

To change the environment through command line I'm using below command

mvn test -Dkarate.env=production -Dtest=PcadSanityTestReport

But by default pre_production environment is getting passed

com.intuit.karate - karate.env system property was: pre_production

can anyone help how to pass env in the command line or do I need to create a different runner for different env


Solution

  • I'm not sure I understand. You override the value with

    System.setProperty("karate.env", "pre_production");
    

    just before you launch the tests, yet you expect the value to be different?

    Edit: Since you seem to want a default value for env, you should do that in karate-config.js

    var env = karate.env;
    //here, you can override env with a default value if the value isn't an authorized one :
    if (env != "pre_production" && env != "production"){
        env = "pre_production";
    }