Karate - How to run a specific scenario only in one environment?

倖福魔咒の 提交于 2019-12-24 06:48:58

问题


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


回答1:


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 :)




回答2:


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



来源:https://stackoverflow.com/questions/54308190/karate-how-to-run-a-specific-scenario-only-in-one-environment

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!