0

I've created a maven project and trying to run Cucumber+Selenium+Java tests using TestNG plugin. While some tutorials that use JUnit+Cucumber shows results with every scenario of a feature, my TestNG results tab shows only the feature name. what am i missing?

I have one feature Authentication Inside that i have two scenarios Login and Logout.

I am expecting something like this in the "Results of Running Suite" tab of 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

BugHunter
  • 61
  • 1
  • 7

2 Answers2

1

the previous answer is right but instead of

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

use

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

else there is an error like that: 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

Community
  • 1
  • 1
-1

If you followed the example given in the cucumber-jvm source (https://github.com/cucumber/cucumber-jvm/blob/master/examples/java-calculator-testng/src/test/java/cucumber/examples/java/calculator/RunCukesByFeatureAndCompositionTest.java), then this will create one test per feature due to the DataProvider:

@DataProvider
public Object[][] features() {
  return testNGCucumberRunner.provideFeatures();
}

If you modify the DataProvider to return scenarios instead, you'll get one testNG test per scenario instead.

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)}};
        }
    }
corinne
  • 318
  • 1
  • 4