问题
I am trying to run specific Gherkin scenarios based on the variable @tags(if it is possible). For example, if my profile is "dev" I want to run scenario 1 and if profile is "qa" I want to run scenario 2. I can get the profile value in my java class. I can also pass the tags in the command line and run it as mentioned here. But that is not something I am looking for. For example:
@QA
Scenario:I do x and check y
Given I do abc
Then the response is 200
@DEV
Scenario:I do y and check x
Given I do cde
Then the response is 500
I am getting the profile value in java class as
System.getProperty("myprofile");
How can I set the tags for cucumber based on my profile so that I can run specific test in specific environment? Basically, I do not want to pass the tags in command line rather want to set it based on my profile. Would it be possible? If not, what would be the best way?
回答1:
I achieved this using maven profile. In each profile, set the cucumber options as
<profiles>
<profile>
<id>development</id>
<properties>
<cucumber.options>
--tags @myTags
</cucumber.options>
<properties>
</profile>
............
</profiles>
Then pass that as System Property variable in the build plugin as
<build>
<plugins>
<plugin>
<configuration>
<systemPropertyVariables>
<cucumber.options>${cucumber.options}</cucumber.options>
</systemPropertyVariables>
</configuration>
<plugin>
</plugins>
</build>
来源:https://stackoverflow.com/questions/45703426/cucumber-tags-based-on-maven-profile