Cucumber 标记为 QAF 和 Spring 引导环境中的 TestNG 组 [英] Cucumber tags as TestNG group in QAF and Spring boot environment

查看:36
本文介绍了Cucumber 标记为 QAF 和 Spring 引导环境中的 TestNG 组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在一个特性文件中有 4 个测试,有 2 个不同的标签 @first 和 @then.我希望@first 测试首先以并行方式运行,@then 测试在所有@first 测试完成后运行,同时也具有并行性.

I have 4 tests in a feature file with 2 different tags @first and @then. I would like @first tests to run first with parallelism and @then tests to run after all @first tests finished, with parallelism too.

项目在这里:https://github.com/marcesso/qafTesting

@CucumberOptions(plugin = {"com.qmetry.qaf.automation.cucumber.QAFCucumberPlugin", "pretty", "html:target"},
        /*tags = {"@Ignore"},*/
        features = {"src/test/resources/my/custom/packagename/testing"})
public class RunnerTest extends AbstractTestNGCucumberTests {

    @Autowired
    private ObjectMapper objectMapper;


    @Test(description = "Runs Cucumber Scenarios", dataProvider = "scenarios", groups = {"first"})
    public void runScenarioFirst(PickleWrapper pickleWrapper, FeatureWrapper featureWrapper) throws Throwable {
        super.runScenario(pickleWrapper,featureWrapper);

    }
    @Test(description = "Runs Cucumber Scenarios", dataProvider = "scenarios", groups = {"then"}, dependsOnMethods =
            "runScenarioFirst")
    public void runScenarioThen(PickleWrapper pickleWrapper, FeatureWrapper featureWrapper) throws Throwable {
        super.runScenario(pickleWrapper,featureWrapper);
    }

    @Override
    @DataProvider(name = "scenarios", parallel = true)
    public Object[][] scenarios() {
        return super.scenarios();
    }

    @PostConstruct
    public void setUp() {
        objectMapper.registerModule(new JavaTimeModule());
    }

}

问题是所有测试都运行两次(每个测试方法一次),并且组"运行了两次.@Test 注释的属性没有按照我的预期过滤测试(在 https://qmetry.github.io/qaf/latest/gherkin_client.html)

The issue is that all tests run twice (once per test method) and the "groups" attribute of @Test annotation does not filter tests as I expected (very bottom at https://qmetry.github.io/qaf/latest/gherkin_client.html)

也根本没有并行性.

我尝试在测试方法中过滤泡菜,但不符合条件的测试即使未运行也显示为通过

I tried to filter pickles in tests methods but tests that did not match the condition were displayed as passed even if not run

if(pickleWrapper.getPickle().getTags().contains("@first")) {
            super.runScenario(pickleWrapper,featureWrapper);
}

推荐答案

在上面的 RunnerTest 示例中,来自 qaf 的 GherkinClient 没有出现,因为您使用的是 Cucumber runner.GherkinScenarioFactoryBDDTestFactory2(使用 qaf 2.1.15+)是 QAF 的 GherkinClient 实现.当你使用它们中的任何一个时,你不需要上面的 RunnerTest 类.BDDTestFactory2 优于 GherkinScenarioFactory,它支持标准 Gherkin 语法之上的附加语法功能.

In above example of RunnerTest, GherkinClient from qaf doesn't come in to picture because you are using cucumber runner. GherkinScenarioFactory and BDDTestFactory2(with qaf 2.1.15+) are GherkinClient implementation of QAF. When you are using any of them, you don't need above RunnerTest class. BDDTestFactory2 is preferred over GherkinScenarioFactory and it supports additional syntax features on top of standard gherkin syntax.

当您使用 Cucumber runner(在您的案例中为 RunnerTest 类)时,标签不被视为 TestNG 组.如果您想使用 Cucumber runner 运行功能文件,您需要使用 cucumber options 来处理它.AFAIK,使用黄瓜跑步者时,您无法通过单一课程实现您所寻找的东西.

When you are using cucumber runner (RunnerTest class in your case), tags are not considered as TestNG groups. If you want to use cucumber runner to run feature file you need to handle it using cucumber options. AFAIK, What you are looking for can't be achieved with single class when using cucumber runner.

当您使用 qaf 时,您可以使用 BDD2Factory 而不是黄瓜测试类.您可以提供考虑场景的 xml 配置作为 TestNG 测试用例.您可以混合和匹配 TestNG 支持的不同配置选项,就像执行用 java 编写的测试一样.在您的情况下,它可能如下所示:

When you are using qaf you can use BDD2Factory instead of cucumber test class. You can provide xml configuration considering scenario as TestNG test case. You can mix and match different configuration options supported by TestNG same as executing Test written in java. In your case it may look like below:

<suite name="QAF Demo" verbose="0" parallel="false" data-provider-thread-count="10">

<test name="First"  parallel="methods"  thread-count="5">
   <groups>
      <run>
        <include name="first" />
      </run>
   </groups>
   <classes>
      <class name="com.qmetry.qaf.automation.step.client.text.BDDTestFactory2" />
   </classes>
</test>

<test name="second"  parallel="methods"  thread-count="5">
   <groups>
      <run>
        <include name="then" />
      </run>
   </groups>
   <classes>
      <class name="com.qmetry.qaf.automation.step.client.text.BDDTestFactory2" />
   </classes>
</test>
</suite>

您也可以使用 元数据过滤器.组/标签也被视为测试用例的元数据卡夫.所以而不是:

You also can utilize metadata filter. Groups/Tags are also considered as meta data of testcase by qaf. So instead of :

<groups>
  <run>
    <include name="first" />
  </run>
</groups>

您可以简单地提供 include 参数如下:

you can simply provide include parameter as below:

   <parameter name="include" value="{'groups': ['first']}" />

我想在此重申,上述功能仅在您使用 BDDTestFactory2 运行时可用,但在使用 Cucumber runner 时不可用.参考 使用 qaf-bdd-runner

I want to reiterate here that above features only available when you are running using BDDTestFactory2 but not available when using cucumber runner. Refer using qaf-bdd-runner

这篇关于Cucumber 标记为 QAF 和 Spring 引导环境中的 TestNG 组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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