0
votes

TestNG Runner class to Execute Multiple Feature Files?

I know we can create a TestNG xml which can target multiple TestNG test classes, but can we create a TestNG.xml which can target multiple Cucumber/ Junit feature files?

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="Cucumber Framework" parallel="classes" thread-count="2">
    <test name="Cucumber Tests">
        <classes>
            <class name="CucumberPIFramework.MainRunner"></class>
        </classes>
    </test>
</suite>
1

1 Answers

1
votes

Yes you should be able to do this in two ways.

Approach 1

You create one java class that looks like below (borrowed from here )

package cucumber.examples.java.calculator;

import cucumber.api.CucumberOptions;
import cucumber.api.testng.AbstractTestNGCucumberTests;

@CucumberOptions(plugin = "json:target/cucumber-report.json")
public class RunCukesTest extends AbstractTestNGCucumberTests {
}

Here you configure the annotation CucumberOptions such that it points to all your .feature files and your glue code.

Approach 2 You create one java class as shown above per .feature file and then create a suite xml file that refers to the package which houses all these java classes.

would that work ?

PS : This will work only with TestNG cucumber integration and not with the JUnit way of running Cucumber tests.