无法在以前工作的脚本上实例化类

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了无法在以前工作的脚本上实例化类相关的知识,希望对你有一定的参考价值。

我有一个简单的框架已经工作,但当我尝试运行该脚本时,我得到一个'无法实例化类'错误

我在我的笔记本电脑上运行它并且它可以工作,但是在我的电脑上我得到了下面的错误,所以我怀疑这可能是一个设置问题,但我不确定从哪里开始修复它。

这是我的“家庭步骤”

package steps;

import cucumber.api.java.en.Given;
import cucumber.api.java.en.Then;
import pages.CheckboxesPage;
import pages.DropdownPage;
import pages.HomePage;
import support.SeleniumSetup;

public class HomeSteps extends SeleniumSetup {

    public HomeSteps() throws Exception{
        prepareBrowserForSelenium();
    }

    @Given("^I am on the herokuapp page "(.*?)"$")
    public void i_am_on_the_herokuapp_page(String arg1) throws Throwable {

        if (arg1.equals("landing page")) { 
            new HomePage(driver).automationLandingPage();
        }

        else if(arg1.equalsIgnoreCase("Checkboxes")) {
            new CheckboxesPage(driver).landingPage();
        }

        else if (arg1.equals ("Dropdown page")) {
            new DropdownPage(driver).verifyLandingPageCopy();
        }
        }

    @Then("^I will be able to select ab testing$")
    public void i_will_be_able_to_select_ab_testing() throws Throwable {
        // Write code here that turns the phrase above into concrete actions
        new HomePage(driver).selectABLink();
    }



}

这是返回的错误

WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by cucumber.deps.com.thoughtworks.xstream.converters.collections.TreeMapConverter (file:/C:/Users/awalker/.m2/repository/info/cukes/cucumber-jvm-deps/1.0.3/cucumber-jvm-deps-1.0.3.jar) to field java.util.TreeMap.comparator
WARNING: Please consider reporting this to the maintainers of cucumber.deps.com.thoughtworks.xstream.converters.collections.TreeMapConverter
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release

1 Scenarios ([31m1 failed[0m)
4 Steps ([31m1 failed[0m, [36m3 skipped[0m)
0m0.236s

cucumber.runtime.CucumberException: Failed to instantiate class steps.HomeSteps
    at cucumber.runtime.java.DefaultJavaObjectFactory.cacheNewInstance(DefaultJavaObjectFactory.java:40)
    at cucumber.runtime.java.DefaultJavaObjectFactory.getInstance(DefaultJavaObjectFactory.java:26)
    at cucumber.runtime.java.JavaStepDefinition.execute(JavaStepDefinition.java:37)
    at cucumber.runtime.StepDefinitionMatch.runStep(StepDefinitionMatch.java:37)
    at cucumber.runtime.Runtime.runStep(Runtime.java:298)
    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:48)
    at cucumber.runtime.junit.ExecutionUnitRunner.run(ExecutionUnitRunner.java:91)
    at cucumber.runtime.junit.FeatureRunner.runChild(FeatureRunner.java:63)
    at cucumber.runtime.junit.FeatureRunner.runChild(FeatureRunner.java:18)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
    at cucumber.runtime.junit.FeatureRunner.run(FeatureRunner.java:70)
    at cucumber.api.junit.Cucumber.runChild(Cucumber.java:93)
    at cucumber.api.junit.Cucumber.runChild(Cucumber.java:37)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
    at cucumber.api.junit.Cucumber.run(Cucumber.java:98)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:89)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:41)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:541)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:763)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:463)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:209)
Caused by: java.lang.reflect.InvocationTargetException
    at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:490)
    at cucumber.runtime.java.DefaultJavaObjectFactory.cacheNewInstance(DefaultJavaObjectFactory.java:34)
    ... 32 more
Caused by: java.lang.IllegalStateException: The driver executable does not exist: C:UsersSelenium and driverschromedriver.exe
    at com.google.common.base.Preconditions.checkState(Preconditions.java:197)
    at org.openqa.selenium.remote.service.DriverService.checkExecutable(DriverService.java:121)
    at org.openqa.selenium.remote.service.DriverService.findExecutable(DriverService.java:116)
    at org.openqa.selenium.chrome.ChromeDriverService.access$000(ChromeDriverService.java:32)
    at org.openqa.selenium.chrome.ChromeDriverService$Builder.findDefaultExecutable(ChromeDriverService.java:137)
    at org.openqa.selenium.remote.service.DriverService$Builder.build(DriverService.java:290)
    at org.openqa.selenium.chrome.ChromeDriverService.createDefaultService(ChromeDriverService.java:88)
    at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:116)
    at support.SeleniumSetup.setup(SeleniumSetup.java:39)
    at support.SeleniumSetup.prepareBrowserForSelenium(SeleniumSetup.java:28)
    at steps.HomeSteps.<init>(HomeSteps.java:13)
    ... 37 more

我希望对以下主页进行简要验证

http://the-internet.herokuapp.com

答案

它在这里陈述

Caused by: java.lang.IllegalStateException: The driver executable does not exist: C:UsersSelenium and driverschromedriver.exe

它基本上找不到您的chromedriver.exe文件。笔记本电脑与您正在尝试使用的PC的文件路径可能不同。

以上是关于无法在以前工作的脚本上实例化类的主要内容,如果未能解决你的问题,请参考以下文章

实例化类的 Python3 问题

Android IntentService 无法实例化类;没有空的构造函数

升级后 Eclipse“无法实例化类 JavaSourceLookupDirector,在分支目标 53 处期望堆栈图帧”

无法实例化类 _TtC12STracker23InfoInterfaceController

寻找在动态加载 Jar 文件和在 Java 运行时实例化类时使用 Apache Felix 的基本示例

模拟问题:无法实例化类的代理:Microsoft.AspNetCore.Identity.UserManager`