CucumberException:无法实例化类stepdef-无法运行功能文件

时间:2019-08-06 17:35:01

标签: java selenium automation cucumber

我正在尝试使用Cucumber的功能文件运行自动化测试。运行功能文件后,我得到:

cucumber.runtime.CucumberException: Failed to instantiate class stepdefs.DashboardWidgets.PMovers
at cucumber.fallback.runtime.java.DefaultJavaObjectFactory.cacheNewInstance(DefaultJavaObjectFactory.java:45)

我有一个由另一个实习生制作的帮助程序文件,其中包括诸如在其构造函数中初始化实际ChromDriver的帮助程序方法。奇怪的是,所有这些测试都是在一个月前进行的,但是当我切换回该分支时,却遇到了很多奇怪的问题。

我尝试更新chromedriver版本,开始一个新项目,进行全新整洁的重建,并查看我的依赖项。

这是我正在谈论的GeneralFactory帮助器类的摘要,当它到达this.driver = new ChromeDriver()行时,将引发错误:

public class GeneralFactory {
    /*
    General factory class that contains functions used by all stepdefs
     */
    public ChromeDriver driver;

    public GeneralFactory() {
        this.driver = new ChromeDriver();
    }

    public void login_to_desktop() {
        //driver.manage().window().maximize();
        driver.get("https://develop.q4desktop.com/");
        LoginPage loginPage = new LoginPage(driver);
        loginPage.loginUserCloseWelcomeNote();
    }

这是我的实际功能文件:

Feature: PeerMovers Widget
  User can use the Peer Movers widget

  Background: User can add a Peer Movers widget
    Given the user can login to test Peer Movers
    Then the user can add a peer movers widget

  Scenario: User can see the peer movers page
   When the peer movers widget loads in
   Then the user can see the peer movers widget

如您所见,这是一些非常简单的内容,现在是与此功能文件相关联的实际Java文件片段:

 public GeneralFactory factory = new GeneralFactory();
    private String peerName;

    @Given("^the user can login to test Peer Movers$")
    public void login_() {
        factory.login_to_desktop();
    }

    @Then("^the user can add a peer movers widget$")
    public void addPeerAlertsWidget() {
        DashBoardWidgetPage dashBoardWidgetPage = new DashBoardWidgetPage(factory.getDriver());
        dashBoardWidgetPage.goToNewDashboardPage();
        dashBoardWidgetPage.addPeerMoverToDashboardPage();
    }

    @When("^the peer movers widget loads in$")
    public void peerMoversLoaded(){
        PeerMoversWidget peerMoversWidget = new PeerMoversWidget(factory.getDriver());
        peerMoversWidget.waitForElement(peerMoversWidget.getItemNames());
    }

    @Then("^the user can see the peer movers widget$")
    public void canSeePeerMovers(){
        PeerMoversWidget peerMoversWidget = new PeerMoversWidget(factory.getDriver());
        Assert.assertTrue("The user does not see the Peer Movers Widget", peerMoversWidget.
                getValues() != null);
    }

完整错误可以在这里看到:

cucumber.runtime.CucumberException: Failed to instantiate class stepdefs.DashboardWidgets.PMovers
at cucumber.fallback.runtime.java.DefaultJavaObjectFactory.cacheNewInstance(DefaultJavaObjectFactory.java:45)
  at cucumber.fallback.runtime.java.DefaultJavaObjectFactory.getInstance(DefaultJavaObjectFactory.java:31)
  at cucumber.runtime.java.JavaStepDefinition.execute(JavaStepDefinition.java:35)
  at cucumber.runtime.StepDefinitionMatch.runStep(StepDefinitionMatch.java:38)
  at cucumber.runtime.Runtime.runStep(Runtime.java:256)
  at cucumber.runtime.model.StepContainer.runStep(StepContainer.java:44)
  at cucumber.runtime.model.StepContainer.runSteps(StepContainer.java:39)
  at cucumber.runtime.model.CucumberScenario.runBackground(CucumberScenario.java:45)
  at cucumber.runtime.model.CucumberScenario.run(CucumberScenario.java:34)
  at cucumber.runtime.model.CucumberFeature.run(CucumberFeature.java:112)
  at cucumber.runtime.Runtime.run(Runtime.java:95)
  at cucumber.runtime.Runtime.run(Runtime.java:83)
  at cucumber.cli.Main.run(Main.java:20)
  at cucumber.cli.Main.main(Main.java:12)
Caused by: java.lang.reflect.InvocationTargetException
  at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
  at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
  at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
  at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
  at cucumber.fallback.runtime.java.DefaultJavaObjectFactory.cacheNewInstance(DefaultJavaObjectFactory.java:39)
  ... 13 more
Caused by: org.openqa.selenium.SessionNotCreatedException: Unable to create new remote session. desired capabilities = Capabilities [{browserName=chrome, chromeOptions=org.openqa.selenium.chrome.ChromeOptions@1b550c0, version=, platform=ANY}], required capabilities = Capabilities [{}]
Build info: version: '3.3.1', revision: '5234b325d5', time: '2017-03-10 09:10:29 +0000'
System info: host: 'START', ip: '192.168.13.164', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_211'
Driver info: driver.version: ChromeDriver
  at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:126)
  at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:141)
  at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:82)
  at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:604)
  at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:244)
  at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:131)
  at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:144)
  at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:170)
  at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:159)
  at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:116)
  at stepdefs.GeneralFactory.<init>(GeneralFactory.java:21)
  at stepdefs.DashboardWidgets.PMovers.<init>(PMovers.java:24)
  ... 18 more

0 个答案:

没有答案