I have a Scenario Outline which has 2 tags @Smoke and @Regression. Inside the Scenario Outline there is a simple Http GET call. We have assigned 2 different tags to the same Scenario Outlie because api is same for both smoke and regression and there are minute differences in the datasource i.e in the headers. Is there any way we can switch the inputs or datasource depending on the tag we trigger at run time?
I strongly recommend not overcomplicating tests like this. As of now, there is no way to get the tags that were used on the command-line. The recommendation is to use the karate.env
and then do some conditional logic in karate-config.js
, you can then set some variables. Using the variables in your tests is then up to you.
Also see Environment Tags: https://github.com/karatelabs/karate#environment-tags
For completeness - karate.tags
will get you the tags for the currently running Scenario
: https://github.com/karatelabs/karate#karate-tags
Example:
@smoke
Scenario:
* def headerJson = {}
* if (karate.tags.includes('smoke')) headerJson.foo = 'bar'
* url 'https://httpbin.org/anything'
* headers headerJson
* method get