当前位置: 首页 > 知识库问答 >
问题:

Selenium:AbstractMethod启动GeckoDriver createArgs()时出错

江天宇
2023-03-14

我收到了一个奇怪的错误,我在其他任何地方都找不到。我只是试图启动GeckoDRiver来启动Firefox。我自己试过了,得到了下面的错误:

错误消息:

"测试时出错:java.lang.AbstractMethodError:接收器类org . open QA . selenium . Firefox . geckodriverservice $ Builder未定义或继承抽象类org . open QA . selenium . remote . service . driver service $ Builder的已解析方法' abstract Java . util . list create args()'的实现。"

我拉下了我正在复制的教程 git,将相同的 GeckoDriver exe 插入文件结构并运行测试运行 - 加载 GeckoDriver 并按预期启动 Firefox。

我去掉了任何无关的东西,复制了我能从教程中看到的所有东西,仍然得到同样的错误。对我来说,通常是一些很小的事情导致了这些类型的事情,但看起来好像应该是有效的。

getDriver方法:

    public WebDriver getFirefoxDriver() {
        setProperty("webdriver.gecko.driver", "src/main/resources/geckodriver");
        WebDriver driver = new FirefoxDriver();
        driver.manage().window().maximize();
        return driver;
    }
Test Class: 
import browser.BrowserGetter;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.TestInstance;
import org.openqa.selenium.WebDriver;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;

@TestInstance(TestInstance.Lifecycle.PER_CLASS)
public class UITests {
    private final BrowserGetter browserGetter = new BrowserGetter();
    private WebDriver driver;

    @BeforeAll
    public void beforeTest(){
        driver = browserGetter.getFirefoxDriver();
    }

    @Test
    public void login() throws InterruptedException {
        driver.get("https://the-internet.herokuapp.com/");
        String expectedTitle = "Something here";
        Thread.sleep(50000);
        //Assertions.assertEquals(expectedTitle, driver.getTitle());
    }
    @AfterAll
    public void afterTest(){
        driver.quit();
    }
}

pom.xml

<?xml version="1.0" encoding="UTF-8"?>

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>org.example</groupId>
  <artifactId>javastudy</artifactId>
  <version>1.0-SNAPSHOT</version>

  <name>javastudy</name>
  <!-- FIXME change it to the project's website -->
  <url>http://www.example.com</url>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.compiler.source>1.7</maven.compiler.source>
    <maven.compiler.target>1.7</maven.compiler.target>
    <kotlin.version>1.4.10</kotlin.version>
  </properties>

  <dependencies>
    <dependency>
      <groupId>org.junit.jupiter</groupId>
      <artifactId>junit-jupiter-api</artifactId>
      <version>5.4.0</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.seleniumhq.selenium</groupId>
      <artifactId>selenium-java</artifactId>
      <version>3.141.59</version>
    </dependency>
    <dependency>
      <groupId>org.apache.commons</groupId>
      <artifactId>commons-lang3</artifactId>
      <version>3.6</version>
    </dependency>
  </dependencies>
</project>

完整的错误消息堆栈跟踪:

java.lang.AbstractMethodError: Receiver class org.openqa.selenium.firefox.GeckoDriverService$Builder does not define or inherit an implementation of the resolved method 'abstract java.util.List createArgs()' of abstract class org.openqa.selenium.remote.service.DriverService$Builder.
    at org.openqa.selenium.remote.service.DriverService$Builder.build(DriverService.java:412)
    at org.openqa.selenium.firefox.FirefoxDriver.toExecutor(FirefoxDriver.java:190)
    at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:147)
    at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:125)
    at browser.BrowserGetter.getFirefoxDriver(BrowserGetter.java:37)
    at UITests.beforeTest(UITests.java:16)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:64)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:564)
    at org.junit.platform.commons.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:688)
    at org.junit.jupiter.engine.execution.MethodInvocation.proceed(MethodInvocation.java:60)
    at org.junit.jupiter.engine.execution.InvocationInterceptorChain$ValidatingInvocation.proceed(InvocationInterceptorChain.java:131)
    at org.junit.jupiter.engine.extension.TimeoutExtension.intercept(TimeoutExtension.java:149)
    at org.junit.jupiter.engine.extension.TimeoutExtension.interceptLifecycleMethod(TimeoutExtension.java:126)
    at org.junit.jupiter.engine.extension.TimeoutExtension.interceptBeforeAllMethod(TimeoutExtension.java:68)
    at org.junit.jupiter.engine.execution.ExecutableInvoker$ReflectiveInterceptorCall.lambda$ofVoidMethod$0(ExecutableInvoker.java:115)
    at org.junit.jupiter.engine.execution.ExecutableInvoker.lambda$invoke$0(ExecutableInvoker.java:105)
    at org.junit.jupiter.engine.execution.InvocationInterceptorChain$InterceptedInvocation.proceed(InvocationInterceptorChain.java:106)
    at org.junit.jupiter.engine.execution.InvocationInterceptorChain.proceed(InvocationInterceptorChain.java:64)
    at org.junit.jupiter.engine.execution.InvocationInterceptorChain.chainAndInvoke(InvocationInterceptorChain.java:45)
    at org.junit.jupiter.engine.execution.InvocationInterceptorChain.invoke(InvocationInterceptorChain.java:37)
    at org.junit.jupiter.engine.execution.ExecutableInvoker.invoke(ExecutableInvoker.java:104)
    at org.junit.jupiter.engine.execution.ExecutableInvoker.invoke(ExecutableInvoker.java:98)
    at org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor.lambda$invokeBeforeAllMethods$9(ClassBasedTestDescriptor.java:384)
    at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
    at org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor.invokeBeforeAllMethods(ClassBasedTestDescriptor.java:382)
    at org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor.before(ClassBasedTestDescriptor.java:196)
    at org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor.before(ClassBasedTestDescriptor.java:78)
    at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$5(NodeTestTask.java:136)
    at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
    at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$7(NodeTestTask.java:129)
    at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:137)
    at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:127)
    at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
    at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:126)
    at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:84)
    at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
    at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:38)
    at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$5(NodeTestTask.java:143)
    at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
    at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$7(NodeTestTask.java:129)
    at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:137)
    at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:127)
    at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
    at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:126)
    at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:84)
    at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.submit(SameThreadHierarchicalTestExecutorService.java:32)
    at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor.execute(HierarchicalTestExecutor.java:57)
    at org.junit.platform.engine.support.hierarchical.HierarchicalTestEngine.execute(HierarchicalTestEngine.java:51)
    at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:108)
    at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:88)
    at org.junit.platform.launcher.core.EngineExecutionOrchestrator.lambda$execute$0(EngineExecutionOrchestrator.java:54)
    at org.junit.platform.launcher.core.EngineExecutionOrchestrator.withInterceptedStreams(EngineExecutionOrchestrator.java:67)
    at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:52)
    at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:96)
    at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:75)
    at com.intellij.junit5.JUnit5IdeaTestRunner.startRunnerWithArgs(JUnit5IdeaTestRunner.java:71)
    at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:33)
    at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:220)
    at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:53)

共有1个答案

融修平
2023-03-14

尝试下载不同版本的驱动程序。并在这里设置:set property(" web driver . gecko . driver "," src/main/resources/geckodriver ");为我工作的chtome driver。现在使用https://chromedriver.storage.googleapis.com/index.html?path=86.0.4240.22/版本。

 类似资料:
  • 我在清单文件中为我的一个活动定义了一个意图过滤器。当我试图使用以下命令从adb外壳启动此活动时: $adb shell am start 我得到以下错误: 开始:Intent{act=android.Intent.action.VIEW dat=http://www.example.com/gizmospkg=com。实例Android} 错误:活动未启动,无法解析Intent{act=andro

  • 我在模拟器上运行一个Android应用程序。它一直工作到昨天和今天我更新了Android Studio。我得到以下错误。如何解决? 模拟器:警告:将内存大小增加到1GB模拟器:错误: x86仿真目前需要硬件加速!请确保英特尔HAXM已正确安装并可用。CPU加速状态:HAXM必须更新(版本1.1.1

  • 我已经从主网站安装了卡桑德拉。每次我尝试启动它时,我总是得到一个错误 Java HotSpot(TM)64位服务器VM警告:Info:OS::Commit_Memory(0x00007F85B2000000,33554432,0)失败;error=“无法分配内存”(errno=12) OS:distrib_id=Ubuntu distrib_release=14.04 distrib_codena

  • 我试图在xampp控制面板v3.2.1上用xampp 1.8.3启动tomcat,但出现了以下错误: Tomcat启动/停止错误,返回代码:1确保您安装了JavaJDK或JRE,并且所需的端口是免费的查看“/xampp/tomcat/logs”文件夹了解更多信息 谁能帮帮我?我正在用windows 7 如果我的英语不完美,我很抱歉

  • 学习Apache Camel-尝试在jboss-fuse-6.1.0.redhat上部署应用程序-379。 POM如下 在数据库配置文件中配置了以下内容 并在路由中调用了sql组件 在引信上部署时- 已经使用wrap:install安装了jar,仍然出现上述错误 请帮我弄清楚。谢谢

  • 当我想跑的时候 运行测试 我总是收到一条错误信息,maven surefire错误出现在starring fork中。这与我的本地设置有关,在我同事的电脑上工作正常。我希望有人知道我的电脑出了什么问题:) 错误消息的一部分: > [错误]无法执行目标组织。阿帕奇。专家插件:maven surefire插件:2.12.4:project exercise00-assignment01上的测试(默认测