Selenium/Cucumber 文件夹迁移后看不到步骤定义

Selenium/Cucumber not seeing step definitions after folder migration

用于此的依赖项:

cucumber-core-1.2.4 cucumber.html-0.2.3 黄瓜-java-1.2.4 黄瓜-junit-1.2.4 junit-4.11 小黄瓜-2.12.2 黄瓜-jvm-deps-1.0.3

我最近清理了我的依赖项文件夹结构,我想我可能放错了什么地方,但我的问题是一个没有意义的实例化问题,因为我似乎在黄瓜边排成一排。这是堆栈跟踪:

cucumber.runtime.CucumberException: Failed to instantiate class cucumber.feature.LoginandMeetingCreation
at cucumber.runtime.java.DefaultJavaObjectFactory.cacheNewInstance(DefaultJavaObjectFactory.java:46)
at cucumber.runtime.java.DefaultJavaObjectFactory.getInstance(DefaultJavaObjectFactory.java:32)
at cucumber.runtime.java.JavaStepDefinition.execute(JavaStepDefinition.java:38)
at cucumber.runtime.StepDefinitionMatch.runStep(StepDefinitionMatch.java:37)
at cucumber.runtime.Runtime.runStep(Runtime.java:299)
at cucumber.runtime.model.StepContainer.runStep(StepContainer.java:44)
at cucumber.runtime.model.StepContainer.runSteps(StepContainer.java:39)
at cucumber.runtime.model.CucumberScenario.run(CucumberScenario.java:44)
at cucumber.runtime.model.CucumberFeature.run(CucumberFeature.java:165)
at cucumber.runtime.Runtime.run(Runtime.java:121)
at cucumber.api.cli.Main.run(Main.java:36)
at cucumber.api.cli.Main.main(Main.java:18)
Caused by: java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
    at java.lang.reflect.Constructor.newInstance(Unknown Source)
    at cucumber.runtime.java.DefaultJavaObjectFactory.cacheNewInstance(DefaultJavaObjectFactory.java:40)
    ... 11 more
Caused by: java.lang.NullPointerException
    at com.google.common.base.Preconditions.checkNotNull(Preconditions.java:770)
    at org.openqa.selenium.support.ui.FluentWait.<init>(FluentWait.java:96)
    at org.openqa.selenium.support.ui.WebDriverWait.<init>(WebDriverWait.java:71)
    at org.openqa.selenium.support.ui.WebDriverWait.<init>(WebDriverWait.java:45)
    at cucumber.feature.LoginandMeetingCreation.<init>(LoginandMeetingCreation.java:19)
    ... 16 more

这是我的 cucumber runner,它设置了特征文件,但从不执行 glue 命令。我的包 cucumber.feature 包含我的步骤定义文件 LoginandMeetingCreation.java 文件:

    package cucumberInitialization;

import org.junit.runner.RunWith;
import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;



@RunWith(Cucumber.class)
@CucumberOptions(
        plugin = {"pretty" , "json:target/cucumber.json"},
        features = {"src/cucumber/"},
        monochrome = true,
        glue = {"cucumber.feature"}


        )
public class cucumberRunner {

}

具有以下步骤的功能文件:

Feature: Create a meeting and fill in the necessary text fields

Scenario: As a user, login and create a meeting

    Given I navigated to the site
    When I login and select an org
    Then Create a meeting

最后是我的步骤定义:

package cucumber.feature;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;

import cucumber.api.PendingException;
import cucumber.api.java.en.Given;
import cucumber.api.java.en.Then;
import cucumber.api.java.en.When;

public class LoginandMeetingCreation {

    WebDriver chromeDriver = null;
    WebDriver ieDriver = null;



    //open IE and Chrome browsers and go to Website
    @Given("^I navigated to the site$")
    public void navigateToWebsite() throws Throwable{
    throw new PendingException();   
    }

    //login users
    @When("^I login and select an org$")
    public void userLogin() throws Throwable{
    throw new PendingException();
    }

    @Then("^Create a meeting$")
    public void meetingCreation() throws Throwable{

        throw new PendingException();

    }
}

有什么建议吗?

感谢 GalexMES。

你是对的,我忘记了我已经删除了大量内容,我突然意识到我正在创建一个不能接受空值的对象。当我写 WebDriverWait wait = new WebDriverWait(ieDriver, 5); 时,ieDriver 为 null,这会导致 NPE。一旦我从非空值创建 ieDriver 对象,就会执行预期的行为。