我创建了一个maven项目并尝试使用TestNG插件运行Cucumber + Selenium + Java测试。虽然一些使用JUnit + Cucumber的教程显示了功能的每个场景的结果,但我的TestNG结果选项卡仅显示功能名称。我错过了什么?
我有一个功能身份验证 在里面我有两个方案登录和注销。
我期待在TestNG的“运行套件的结果”标签中出现类似的情况: From a JUnit tutorial
答案 0 :(得分:1)
之前的回答是对的,但是 而不是
scenarioList.add(new Object[]{scenario, scenario.getGherkinModel().getName()});
使用
scenarioList.add(new Object[]{scenario});
答案 1 :(得分:-1)
如果您按照cucumber-jvm源(https://github.com/cucumber/cucumber-jvm/blob/master/examples/java-calculator-testng/src/test/java/cucumber/examples/java/calculator/RunCukesByFeatureAndCompositionTest.java)中给出的示例,那么由于DataProvider,这将为每个功能创建一个测试:
@DataProvider
public Object[][] features() {
return testNGCucumberRunner.provideFeatures();
}
如果您修改DataProvider以返回场景,那么您将在每个场景中获得一次testNG测试。
public List<CucumberFeature> getFeatures() {
return runtimeOptions.cucumberFeatures(resourceLoader);
}
public Object[][] provideScenarios() {
try {
List<CucumberFeature> features = getFeatures();
List<Object[]> scenarioList = new ArrayList<Object[]>(features.size());
for (CucumberFeature feature : features) {
List<CucumberTagStatement> scenarios = feature.getFeatureElements();
for (CucumberTagStatement scenario : scenarios) {
// If this is a Scenario Outline, split it up so each one is a test.
if (scenario instanceof CucumberScenarioOutline) {
List<CucumberExamples> cucumberExamplesList = ((CucumberScenarioOutline) scenario).getCucumberExamplesList();
for (CucumberExamples cucumberExamples : cucumberExamplesList) {
List<CucumberScenario> exampleScenarios = cucumberExamples.createExampleScenarios();
for (CucumberScenario exampleScenario : exampleScenarios) {
scenarioList.add(new Object[]{exampleScenario, exampleScenario.getGherkinModel().getName()});
}
}
} else
scenarioList.add(new Object[]{scenario, scenario.getGherkinModel().getName()});
}
}
return scenarioList.toArray(new Object[][]{});
} catch (CucumberException e) {
return new Object[][]{new Object[]{new CucumberExceptionWrapper(e)}};
}
}