jimbaker
jimbaker

Reputation: 115

Modify CucumberOptions tags when running Cucumber in Java

I was wondering if there was a way to modify CucumberOptions tags while Cucumber is running?

I'm not sure if this is possible or not but I was wondering if there was a way to modify tags while Cucumber is running. In my example code, I would like to add another tag "@Login" once Cucumber runs. I am trying to setup a configuration where I can select which feature I want to run without going into the Runner class.

Settings Class

 String AddTags = "@Login";
          set = new HashMap<String, String>(){
            {put("Tags", AddTags);

Runner

import org.junit.runner.RunWith;
import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;

@RunWith(Cucumber.class) 
@CucumberOptions (features="src/test/cucumber/features", 
tags = "@Smoke",  //For instance, once cucumber runs I want to add 
tag "@Login". //So something like adding Settings.set.get("Tags");
plugin = {"pretty", "html:target/cucumber- 
htmlreport","json:target/cucumber-report.json"}
)
public class Runner {

}

Not sure if this is possible with Cucumber but wanted to ask.

Upvotes: 4

Views: 10487

Answers (2)

Marit
Marit

Reputation: 3026

You can use Tag expressions to combine several tags, for example:

**Expression        Description**
@fast               Scenarios tagged with @fast
@wip and not @slow  Scenarios tagged with @wip that aren’t also tagged with @slow
@smoke and @fast    Scenarios tagged with both @smoke and @fast
@gui or @database   Scenarios tagged with either @gui or @database

Upvotes: 3

Reimeus
Reimeus

Reputation: 159784

What about using a list of tags?

tags = "@Smoke,@Login"

Upvotes: 0

Related Questions