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

为君一笑 提交于 2021-02-16 20:22:05

问题


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 forexample: tagename.

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 is anyone can provide me with 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.


回答1:


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"




回答2:


You need to add this

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

}

And CLI command will be

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


来源:https://stackoverflow.com/questions/56376470/cucumber-test-execution-for-gradle-project-via-command-line-using-tags-for-cucum

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