将testng与黄瓜整合时出现问题

时间:2018-07-12 11:02:00

标签: java selenium cucumber testng cucumber-java

当我用testng跑黄瓜时,出现以下错误。

在这种情况下,请让我知道为什么会跳过测试并出现nullpointer错误。我已多次检查代码。如果我在这里缺少什么,请告诉我。我在下面粘贴了代码和错误。 总错误粘贴到下面:-

  

跳过:方案            运行黄瓜方案   java.lang.RuntimeException:java.lang.NullPointerException       在org.testng.internal.MethodInvocationHelper.invokeDataProvider(MethodInvocationHelper.java:162)       在org.testng.internal.Parameters.handleParameters(Parameters.java:430)       在org.testng.internal.Invoker.handleParameters(Invoker.java:1270)       在org.testng.internal.Invoker.createParameters(Invoker.java:985)       在org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1075)       在org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:125)       在org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:108)       在org.testng.TestRunner.privateRun(TestRunner.java:774)       在org.testng.TestRunner.run(TestRunner.java:624)       在org.testng.SuiteRunner.runTest(SuiteRunner.java:359)       在org.testng.SuiteRunner.runSequentially(SuiteRunner.java:354)       在org.testng.SuiteRunner.privateRun(SuiteRunner.java:312)       在org.testng.SuiteRunner.run(SuiteRunner.java:261)       在org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)       在org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)       在org.testng.TestNG.runSuitesSequentially(TestNG.java:1215)       在org.testng.TestNG.runSuitesLocally(TestNG.java:1140)       在org.testng.TestNG.run(TestNG.java:1048)       在org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:132)       在org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:236)       在org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:81)   造成原因:java.lang.NullPointerException       在cucumber.api.testng.AbstractTestNGCucumberTests.scenarios(AbstractTestNGCucumberTests.java:44)       在sun.reflect.NativeMethodAccessorImpl.invoke0(本机方法)处       在sun.reflect.NativeMethodAccessorImpl.invoke(未知来源)       在sun.reflect.DelegatingMethodAccessorImpl.invoke(未知来源)       在java.lang.reflect.Method.invoke(未知来源)       在org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:85)       在org.testng.internal.MethodInvocationHelper.invokeDataProvider(MethodInvocationHelper.java:136)       ...另外20个

请检查TestRunner代码:-

@CucumberOptions(features = "src\\bbd_feature",glue="stepdef",
    tags = {"~@Ignore"}, plugin = {"json:test-output/cucumber-report/report2.json", 
    "html:test-output/cucumber-report/report2.html"},
format = {
        "pretty",
        "html:target/cucumber-reports/cucumber-pretty",
        "json:target/cucumber-reports/CucumberTestReport.json",
        "rerun:target/cucumber-reports/rerun.txt"
})
public class TestRunner extends AbstractTestNGCucumberTests{

    private TestNGCucumberRunner testNGCucumberRunner;

    @BeforeClass(alwaysRun = true)
    public void setUpClass() throws Exception {
        testNGCucumberRunner = new TestNGCucumberRunner(this.getClass());
    }

    @Test(groups = "cucumber", description = "Runs Cucumber Feature", dataProvider = "features")
    public void feature(CucumberFeatureWrapper cucumberFeature) {
        testNGCucumberRunner.runCucumber(cucumberFeature.getCucumberFeature());
    }

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

    @AfterClass(alwaysRun = true)
    public void tearDownClass() throws Exception {
        testNGCucumberRunner.finish();
    }

}

步骤def的代码:-

public class stepdefinition 
{

    @Given("^I work in weekends$")
    public void test1() throws Throwable
    {
        System.out.println("Test Given 1");
    }

    @When("^During Daytime$")
    public void test2() throws Throwable
    {
        System.out.println("Test When 2");

    }

    @Then("^I Sleep$")
    public void test3() throws Throwable
    {

        System.out.println("Test Then 3");

    }
}

0 个答案:

没有答案