Consider there are 100 scenarios and I want to run 99 scenarios in prod environment and 100 on stage environment .
Is there a way to achieve this in karate ?
Things I tried 1. Create a feature file with 1 scenario and another feature file with remaining 99 2. Add tag to the 1 scenario file 3. Ignore that while running
But then when I use it in jenkins job I have to run one command to run on both machines so would not work
The best solution for this case is the karate.abort()
API:
So in the "special" scenario #100 - you can do this:
Scenario:
* eval if (karate.env == 'prod') karate.abort()
# normal scenario steps
Please note that there are advanced options for tag selectors in Karate 0.9.0 onwards - but just stick to the solution above please :)
Tag the 100th scenario with @hundred and just run the following command when you want to run 99 scenarios
mvn test -Dkarate.options="--tags ~@hundred"
And simply run mvn test
when you want to run all tests.
You can tag a scenario
@hundred
Scenario: the scenario only played in one case
Given <...>
But you can also tag a Feature
@hundred
Feature: The feature containing the scenario only played in one case
Background:
* <..>
Scenario: <...>
Edit after your answer : You could use a second runtime variable :
mvn test -Dkarate.options="--tags ~@{variable2}" -Dkarate.env={variable}
Or even use the same runtime variable :
mvn test -Dkarate.options="--tags ~@{variable}" -Dkarate.env={variable}
And that maybe wouldn't be the best solution, but you can add @Prod to the 99 scenarios, and @Stage to all of them, and switch the command to this :
mvn test -Dkarate.options="--tags @{variable}" -Dkarate.env={variable}
It's a bit longer to do, but at least the tag(s) on each feature/scenario will correspond to the case(s) in which they are launched
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.