1

I have a requirement where in need to fetch karate-config.js data in my junit test runner to execute feature files based on conditional logic

karate-config.js file:-

    config.ACH = "Yes" 
    config.VISA = "No"
    config.MasterCard = "No"
    config.PAYPAL = "Yes"

I want to implement following logic in test runner java class:-

class default_TestRunner {

    @Karate.Test
    Karate testPostResult() {
        System.setProperty("karate.env", "qa");
if(config.ACH == "Yes" && config.PAYPAL == "Yes") // How to read these config data and exec specific feature files 
        return Karate.run("src/test/java/features/ACHE2E.feature","src/test/java/features/PAYPALE2E.feature").tags("~@ignore");
    
    
    }

}
prem gupta
  • 11
  • 2

1 Answers1

0

What you are asking for is not supported and in my opinion the wrong approach. If you want to conditionally run tests depending on how tests are initiated, use tags: https://github.com/karatelabs/karate#tags

There is a way in which you can use the karate.env to select (or un-select) tests. Maybe that's all you need.

Peter Thomas
  • 54,465
  • 21
  • 84
  • 248
  • I am bound to implement this approach as in my case third party commits data in form of "Yes"/"No" in config.js to exec specific feature file. – prem gupta Jul 24 '23 at 11:35
  • I have implemented a approach: Feature: Background: * def execPayouts = """ function(x) { if (ACH == 'Yes') karate.call('classpath:src/test/java/features/ACHE2E.feature'); if (PAYPAL == 'Yes') karate.call('classpath:src/test/java/features/PAYPALE2E.feature'); } """ Scenario: * call execPayouts But if first feature will have failures then second feature will not be executed. – prem gupta Jul 24 '23 at 11:37
  • @premgupta I will just say that there are plenty of other ways to do this in karate. look at examples like this one: https://stackoverflow.com/a/60387907/143475 - but if you insist, all the best with what you are doing. maybe karate is not the right choice for you, just use Java or JS. you should not be mis-using `karate-config.js` like this. – Peter Thomas Jul 24 '23 at 11:40