I have this error:
Caused by: java.lang.NullPointerException: Cannot invoke "io.cucumber.testng.TestNGCucumberRunner.provideScenarios()" because "this.testNGCucumberRunner" is null
at Runner.TestRunner.scenarios(TestRunner.java:36)
FAILED CONFIGURATION: @AfterClass Runner.TestRunner.tearDownClass
java.lang.NullPointerException: Cannot invoke "io.cucumber.testng.TestNGCucumberRunner.finish()" because "this.testNGCucumberRunner" is null
at Runner.TestRunner.tearDownClass(TestRunner.java:41)
at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
at java.base/java.lang.reflect.Method.invoke(Method.java:580)
at org.testng.internal.invokers.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:139)
at org.testng.
here's my runner file unable to execute struggling from past 10 ndays, using all the latest dependencies
@CucumberOptions(
features="src/test/java/features",
glue="sr//test//java//steps"
// plugin={"pretty", "io.qameta.allure.cucumber7jvm.AllureCucumber7Jvm"}
// tags="@Amazon"
)
public class TestRunner {
private TestNGCucumberRunner testNGCucumberRunner;
@BeforeClass(alwaysRun = true)
public void setUpClass() {
testNGCucumberRunner = new TestNGCucumberRunner(this.getClass());
}
@Test(groups = "cucumber", description = "Runs Cucumber Scenarios", dataProvider = "scenarios")
public void scenario(PickleWrapper pickle, FeatureWrapper cucumberFeature) {
testNGCucumberRunner.runScenario(pickle.getPickle());
}
@DataProvider
public Object[][] scenarios() {
return testNGCucumberRunner.provideScenarios();
}
@AfterClass(alwaysRun = true)
public void tearDownClass() {
testNGCucumberRunner.finish();
}
}
@DataProvider(@=data)
public Object[][] scenarios() {
return testNGCucumberRunner.data();
}
Can you help me to fix the code for cucumber with testng?
You actually have a few problems that result in a "nothing is working". So fixing one problem, will not immediately get you something that works.
So the first problem you are looking at is that you have an NPE:
Which means that
testNGCucumberRunnerhere is null (read the stack trace carefully).Which means that it was never initialized, which means that
new TestNGCucumberRunnermust have thrown an exception here:You didn't mention any other exceptions, but if you add a null check to the
tearDownClassyou should see it in the output. And that exception may give you a hint at what your other problems are.