文件夹迁移后,Selenium / Cucumber没有看到步骤定义

时间:2017-03-10 14:10:38

标签: java selenium junit cucumber

用于此的依赖关系:

黄瓜核-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

这是我的黄瓜跑步者设置功能文件,但从不执行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();

    }
}

有什么建议吗?

1 个答案:

答案 0 :(得分:0)

感谢GalexMES。

你是对的,我忘了我已经删除了一大笔金额而且我明白我正在创建一个无法接受空值的对象。当我写WebDriverWait wait = new WebDriverWait(ieDriver, 5); ieDriver为空时,导致NPE。一旦我从非空值创建ieDriver对象,就会执行预期的行为。