I'm looking at running Cucumber tests with TestNG. However I am having a issue where all my Scenario are running as one TestNG @Test
session. Is there a way to run each Scenario as a separate @Test
sessions?
Here is my TestNG xml:
<suite name="cucumber Suites">
<test name="cucumber-testing">
<classes>
<class name="runners.Run2" />
</classes>
</test>
</suite>
This will call run the following Test class:
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import cucumber.api.CucumberOptions;
import cucumber.api.testng.AbstractTestNGCucumberTests;
import cucumber.api.testng.CucumberFeatureWrapper;
import cucumber.api.testng.TestNGCucumberRunner;
@CucumberOptions( features="cucumber/features/example.feature",
glue="steps",
format={"pretty"}
)
public class Run2 extends AbstractTestNGCucumberTests{
private TestNGCucumberRunner tcr;
@BeforeClass(alwaysRun=true)
public void beforeClass() throws Exception{
tcr = new TestNGCucumberRunner(this.getClass());
}
@Test(groups="cucumber", description="Runs CucumberFeature", dataProvider="features")
public void feature(CucumberFeatureWrapper cucumberFeature){
tcr.runCucumber(cucumberFeature.getCucumberFeature());
}
@DataProvider
public Object[][] features(){
return tcr.provideFeatures();
}
@AfterClass (alwaysRun=true)
public void afterClass(){
tcr.finish();
}
}
I am wondering if there is a way to get the @DataProviderto
provide Scenario and the @Test
to run Scenario instead of the features?
The reason for this is that I have other TestNG tests with Listeners and that I want to use the same Listeners, reporting for Cucumber tests.
Thanks