问题描述
我在一个功能文件中有4个测试,带有2个不同的标签@first和@then。 我希望@first测试首先使用并行性运行,而@then测试要在所有@first测试完成后再使用并行性运行。
项目在这里: 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",groups = {"then"},dependsOnMethods =
"runScenarioFirst")
public void runScenarioThen(PickleWrapper pickleWrapper,featureWrapper);
}
@Override
@DataProvider(name = "scenarios",parallel = true)
public Object[][] scenarios() {
return super.scenarios();
}
@PostConstruct
public void setUp() {
objectMapper.registerModule(new JavaTimeModule());
}
}
问题是所有测试都运行两次(每个测试方法一次),并且@Test批注的“ groups”属性未按我的预期过滤测试(在https://qmetry.github.io/qaf/latest/gherkin_client.html的最底部)
也完全没有并行性。
我尝试在测试方法中过滤泡菜,但即使不运行,也不符合条件的测试也会显示为通过
if(pickleWrapper.getPickle().getTags().contains("@first")) {
super.runScenario(pickleWrapper,featureWrapper);
}
解决方法
在上面的RunnerTest
示例中,来自qaf的GherkinClient没有出现在图片中,因为您使用的是黄瓜冲孔器。 GherkinScenarioFactory
和BDDTestFactory2
(带有qaf 2.1.15+)是QAF的GherkinClient实现。使用其中任何一个时,都不需要RunnerTest
类以上的类。 BDDTestFactory2
比GherkinScenarioFactory
更为可取,它支持标准小黄瓜语法之上的其他语法功能。
当您使用黄瓜赛跑者(在您的情况下为RunnerTest
类)时,标记不会被视为TestNG组。如果要使用CucumberRunner运行功能文件,则需要使用黄瓜选项处理它。 AFAIK,在使用黄瓜浇头时,单班无法实现您想要的东西。
使用qaf时,可以使用BDD2Factory代替黄瓜测试班。您可以提供将场景视为TestNG测试用例的xml配置。您可以混合和匹配TestNG支持的不同配置选项,就像执行用Java编写的Test一样。就您而言,它可能如下所示:
<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>
您还可以使用metadata filter。 qaf也将组/标签视为测试用例的meta data。 因此,而不是:
<groups>
<run>
<include name="first" />
</run>
</groups>
您只需提供include
参数,如下所示:
<parameter name="include" value="{'groups': ['first']}" />
我想在此重申,以上功能仅在使用BDDTestFactory2
运行时可用,而在使用黄瓜运行器时不可用。请参阅using qaf-bdd-runner