Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cucumber Test execution for gradle project via command line using tags for cucumber feature files

I am looking to execute a cucumber test for a gradle project via command line using specific feature tags.

The command I am using: gradle test -DCucumber.options="-tags @tagname". Command does execute the tags mentioned. I have tried using gradle test -DCucumber.options="-tags @tagname" and also gradle test. I didn't find any difference in both the command.

gradle test -DCucumber.options="-tags @tagname" executes the Runtest.java and tags mentioned in this file, irrespective of what feature tags I pass via command line for example: tagname.

Runtest.java

@RunWith(Cucumber.class)
@CucumberOptions(features = "src\\test\\resources\\featurefiles", monochrome = true, plugin = {
        "com.eis.listeners.ExtentCucumberFormatter:" }, glue = {
                "com.adminconsole.stepdefs" },tags= {"@adminconsolelogin,@devicemanager,@certificatemanagement"} ,format = { "json:JsonReports/AdminConsole.json" })

So here I have mentioned three tags in the Runtest.java. Now, instead of running all the tags, I wanna run a specific tag via command line. Command: gradle test -DCucumber.options="-tags @adminconsolelogin", but -DCucumber.options="-tags @adminconsolelogin" part ain't working.

I am looking for a solution where we can run specific tags irrespective of what tag is mentioned in Runtest.java. More precisely pass tags dynamically via command line.

But -DCucumber.options="-tags @tagname" ain't working via command line. Would appreciate if anyone can provide me with a correct command or strategy or code on how to do it. If the below command is wrong: gradle test -DCucumber.options="-tags @tagname" please correct me.

like image 972
Angshuman Basak Avatar asked Jan 01 '23 22:01

Angshuman Basak


2 Answers

Update: For Cucumber 6 you need to provide the following statement:

test {
systemProperty "cucumber.filter.tags", System.getProperty("cucumber.filter.tags")

}

You have to bridge the system properties between the gradle JVM and the forked JVM for the tests for this to work. From issue #1346:

test { 
    systemProperty "cucumber.options", System.getProperty("cucumber.options") 
} 

Add that to your build.gradle and then you can do it on the command-line:

gradle test -Dcucumber.options="-tags @tagname"

like image 133
Nick Rundle Avatar answered Jan 04 '23 23:01

Nick Rundle


You need to add this

test { 
systemProperty "cucumber.options", System.getProperty("cucumber.options") 

}

And CLI command will be

gradle test -Dcucumber.options="--tags @tagName"
like image 27
Sobhit Sharma Avatar answered Jan 04 '23 23:01

Sobhit Sharma