我刚刚将现有项目转换为 Maven 项目。我添加了依赖项,如 selenium-java、selenium-serve、selenium-chrome-driver、testing 和 JUnit。
它是一个TestNG项目,包含许多包和类。它给了我一个错误,如下所示:
Exception in thread "main" java.lang.AbstractMethodError: Receiver class org.openqa.selenium.chrome.ChromeDriverService$Builder does not define or inherit an implementation of the resolved method 'abstract void loadSystemProperties()' of abstract class org.openqa.selenium.remote.service.DriverService$Builder.
at org.openqa.selenium.remote.service.DriverService$Builder.build(DriverService.java:504)
at org.openqa.selenium.chrome.ChromeDriverService.createDefaultService(ChromeDriverService.java:162)
at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:52)
我添加的依赖项;
<dependencies>
<!--
https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java -->
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>4.10.0</version>
</dependency>
<!--
https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-server -->
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-server</artifactId>
<version>3.9.0</version>
</dependency>
<!--
https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-chrome-driver-->
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-chrome-driver</artifactId>
<version>4.9.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.testng/testng -->
<dependency>
<groupId>
org.testng</groupId>
<artifactId>testng</artifactId>
<version>7.3.0</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/junit/junit -->
<dependency>
<groupId>
junit</groupId>
<artifactId>junit</artifactId>
<version>4.6</version>
<scope>test</scope>
</dependency>
<!--
https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-support -->
<dependency>
<groupId>
org.seleniumhq.selenium</groupId>
<artifactId>selenium-support</artifactId>
<version>
4.10.0</version>
</dependency>
<!--
https://mvnrepository.com/artifact/ru.stqa.selenium/webdriver-expected-conditions -->
<dependency>
<groupId>ru.stqa.selenium</groupId>
<artifactId>
webdriver-expected-conditions</artifactId>
<version>1.0.41</version>
</dependency>
</dependencies>
我还在我的鳕鱼中添加了这一行,
System.setProperty("webdriver.chrome.driver", "path");
WebDriver driver = new ChromeDriver();
谁能帮我解决这个错误。我该怎么办?
这个错误信息...
Exception in thread "main" java.lang.AbstractMethodError: Receiver class org.openqa.selenium.chrome.ChromeDriverService$Builder does not define or inherit an implementation of the resolved method 'abstract void loadSystemProperties()' of abstract class org.openqa.selenium.remote.service.DriverService$Builder
...暗示类没有实现父类的正确方法。
出现这种情况是因为版本/依赖不匹配。
在您的
pom.xml
中,同一任务有 2 个不同的依赖项。
selenium-java:
https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java -->
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>4.10.0</version>
</dependency>
硒服务器:
https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-server -->
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-server</artifactId>
<version>3.9.0</version>
</dependency>
删除任何一个依赖项,你就可以开始了。