I want to run a basic cucumber feature file as a TestNG test via TestRunner class facilitating a cucumber-testng integration in Intellij.
Please note that I was able to successfully run the cucumber scenarios as cucumber java tests.
But when tried to run the same feature file scenarios via cucumber testNG integration via testrunner class extending AbstractTestNGCucumberTests,the following happens:
No scenarios mentioned in feature file gets executed
Browser does not get launched at all.
Console window says Test passed as shown below
To run as testNG tests, i tried two run configurations in Intellij ,first run the TestRunner class itself ,for that i went to Run configurations- added a template under TestNG and ensured the below:
Test Kind: Class, Class: points to the TestRunner class, VM options: -ea -Dtestng.dtd.http=true , Working Directory: $MODULE_WORKING_DIR$.
Second tried to run the TestNG.xml file from run configurations window: Test Kind: Suite, Class: points to the testNG xml file in project directory, VM options: -ea -Dtestng.dtd.http=true, Working Directory: $MODULE_WORKING_DIR$ .
Note:- getting an error warning "Unable to parse the testNG.xml" in the run Configuration while trying to run the testng.xml file Much appreciated if some one could advise me on what i am missing..
[enter image description here][1]
My POM.xml has the following dependencies:
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-java</artifactId>
<version>6.8.1</version>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-picocontainer</artifactId>
<version>6.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-testng</artifactId>
<version>6.8.1</version>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-jvm-deps</artifactId>
<version>1.0.6</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-core</artifactId>
<version>6.8.1</version>
</dependency>
TestRunner class is :
import io.cucumber.testng.TestNGCucumberRunner;
import io.cucumber.testng.CucumberOptions;
import io.cucumber.testng.AbstractTestNGCucumberTests;
import io.cucumber.testng.FeatureWrapper;
import io.cucumber.testng.CucumberOptions;
import io.cucumber.testng.PickleWrapper;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
//@RunWith( ExtendedCucumber.class)
@CucumberOptions(
features = "classpath:Features",
glue={"com/cucumber/Projects/StepDefinitions"},
tags="@Type1",
dryRun=true,
monochrome=true,
/*plugin = {"html:target/cucumber-html-report",
"json:target/cucumber.json", "pretty:target/cucumber-pretty.txt" ,
"com.cucumber.listener.ExtentCucumberFormatter:target/cucumber-reports/RunResults.html"},*/
plugin = {"html:target/cucumber-html-report","json:target/cucumber.json","pretty:target/cucumber-pretty.txt"},
strict = true)
public class TestRunner extends AbstractTestNGCucumberTests {
private TestNGCucumberRunner testNGCucumberRunner;
@BeforeClass( alwaysRun = true )
public void setUpClass() {
testNGCucumberRunner = new TestNGCucumberRunner( this.getClass() );
}
@Test( groups = "cucumber", description = "Runs Cucumber Feature", dataProvider = "features" )
public void feature( PickleWrapper pickleWrapper,FeatureWrapper cucumberFeature ) {
testNGCucumberRunner.runScenario( pickleWrapper.getPickle());
}
@DataProvider
public Object[][] features() {
return testNGCucumberRunner.provideScenarios();
}
@AfterClass( alwaysRun = true )
public void tearDownClass() {
testNGCucumberRunner.finish();
}
}
TestNGxml file:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "https://testng.org/testng-1.0.dtd">
<suite name="Suite" parallel="instances" thread-count="3">
<test name="testRunner">
<classes>
<class name="com.cucumber.Projects.TestRunner.TestRunner"/>
</classes>
</test>
</suite>
Console window Output:
===============================================
Default Suite
Total tests run: 1, Failures: 0, Skips: 0
=============================================== ```
Process finished with exit code 0 *
[1]: https://i.stack.imgur.com/iDBdR.png