基于 Maven 配置文件的黄瓜标签 [英] cucumber tags based on maven profile

查看:38
本文介绍了基于 Maven 配置文件的黄瓜标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试基于变量 @tags 运行特定的 Gherkin 场景(如果可能的话).例如,如果我的配置文件是dev",我想运行场景 1,如果配置文件是qa",我想运行场景 2.我可以在我的 java 类中获取配置文件值.我也可以在命令行中传递标签并按照 here 中提到的方式运行它.但这不是我要找的东西.例如:

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

我将 java 类中的配置文件值作为

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?

推荐答案

我使用 maven profile 实现了这个.在每个配置文件中,将黄瓜选项设置为

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>

这篇关于基于 Maven 配置文件的黄瓜标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆