【问题标题】:How to make TestNG show cucumber scenarios in the "Results of Running Suite"?如何让TestNG在“运行套件的结果”中显示黄瓜场景?
【发布时间】:2019-02-17 14:46:55
【问题描述】:

我创建了一个 maven 项目并尝试使用 TestNG 插件运行 Cucumber+Selenium+Java 测试。虽然一些使用 JUnit+Cucumber 的教程会显示每个功能场景的结果,但我的 TestNG 结果选项卡仅显示功能名称。我错过了什么?

我有一项功能身份验证 在里面我有两个场景登录和注销。

我期待在 TestNG 的“运行套件的结果”选项卡中出现这样的结果: From a JUnit tutorial

My current testng result is like this. 'Authentication' is the feature, but the 2 scenarios inside it are not appearing

【问题讨论】:

  • 您应该分享您当前的 TestNG 输出以及重现您所描述内容的方法。否则,就像您在寻求教程一样。
  • 我已经用我的输出编辑了

标签: cucumber testng cucumber-junit


【解决方案1】:

前面的答案是对的,但是 而不是

scenarioList.add(new Object[]{scenario, scenario.getGherkinModel().getName()});

使用

scenarioList.add(new Object[]{scenario});

否则会出现这样的错误: Selenium Webdriver, TestNG - data provider is trying to pass 2 parameter but the method take 3 and TestNG is unable in inject a suitable object

【讨论】:

    【解决方案2】:

    如果您按照 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)}};
            }
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-07-17
      • 2017-09-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多