我正试图在Spring启动项目上安装appium-根据这里https://github.com/appium/java-client/blob/master/docs/Installing-the-project.md
当运行一个简单的脚本时,我得到了这个错误:
线程中的异常"主";java.lang.NoClassDefFoundError:org/openqa/selement/internal/Require位于io.apium.java_client.remote.options.BaseOptions.setCapability(BaseOptions.java:144(位于io.apium.java_client.remote.options.CanSetCapability.modify(CanSetCapabibility.java:30(位于io.apium.java_client.remote.options.BaseOptions.setPlatformName(BaseOptions.java:86(位于io.apium.java_client.android.options.UiAutomator2Options.setCommonOptions(UiAutomator 2Options.java:222(位于io.apium.java_client.android.options.UiAutomator2Options.(UiAutomator 2Options.java:208(网址:com.aniview.testService.content.initAppium.main(initAppium.java:25(引起原因:java.lang.ClassNotFoundException:org.openqa.selenium.internal.Require位于java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641(位于java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188(位于java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521(…还有6个
我的脚本:
import io.appium.java_client.AppiumBy;
import io.appium.java_client.AppiumDriver;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.android.options.UiAutomator2Options;
import org.openqa.selenium.WebElement;
import java.net.MalformedURLException;
import java.net.URL;
import java.time.Duration;
import java.util.concurrent.TimeUnit;
public class initAppium {
static AppiumDriver driver;
public static void main(String[] args) throws MalformedURLException, InterruptedException {
URL url = new URL("http://127.0.0.1:4723/wd/hub");
UiAutomator2Options options = new UiAutomator2Options()
.setDeviceName("emulator-5554 (sdk_gphone64_arm64 - Android 12)")
.setUdid("emulator-5554")
.setPlatformName("Android")
.setPlatformVersion("12")
.setChromedriverExecutable("/Users/x/node_modules/appium/node_modules/appium-chromedriver/chromedriver")
.setAppPackage("com.android.chrome")
.setAppActivity("com.google.android.apps.chrome.Main")
.setAutoWebview(true)
.eventTimings();
driver = new AppiumDriver(url, options);
System.out.println("Application started");
}
}
我的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
https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.6.3</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.aniview</groupId>
<artifactId>testService</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>testService</name>
<description>Web service for managing test executions</description>
<properties>
<java.version>18</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.ini4j</groupId>
<artifactId>ini4j</artifactId>
<version>0.5.4</version>
</dependency>
<dependency>
<groupId>com.vaadin.external.google</groupId>
<artifactId>android-json</artifactId>
<version>0.0.20131108.vaadin1</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk</artifactId>
<version>1.11.163</version>
</dependency>
<dependency>
<groupId>com.google.apis</groupId>
<artifactId>google-api-services-sheets</artifactId>
<version>v4-rev493-1.23.0</version>
</dependency>
<dependency>
<groupId>com.google.api-client</groupId>
<artifactId>google-api-client</artifactId>
<version>1.33.0</version>
<exclusions>
<exclusion>
<groupId>com.google.guava</groupId>
<artifactId>com.google.guava</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>com.google.api-client</groupId>
<artifactId>google-api-client-jackson2</artifactId>
<version>1.32.1</version>
</dependency>
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>libraries-bom</artifactId>
<version>25.0.0</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>com.sun.mail</groupId>
<artifactId>javax.mail</artifactId>
<version>1.6.2</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.apis</groupId>
<artifactId>google-api-services-gmail</artifactId>
<version>v1-rev33-1.20.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.json/json -->
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20190722</version>
</dependency>
<!-- https://mvnrepository.com/artifact/javax.mail/mail -->
<dependency>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
<version>1.4.7</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.jsoup/jsoup -->
<dependency>
<groupId>org.jsoup</groupId>
<artifactId>jsoup</artifactId>
<version>1.13.1</version>
</dependency>
<dependency>
<groupId>com.googlecode.json-simple</groupId>
<artifactId>json-simple</artifactId>
<version>1.1</version>
</dependency>
<dependency>
<groupId>com.google.oauth-client</groupId>
<artifactId>google-oauth-client-java6</artifactId>
<version>1.23.0</version>
</dependency>
<dependency>
<groupId>com.google.oauth-client</groupId>
<artifactId>google-oauth-client-jetty</artifactId>
<version>1.23.0</version>
</dependency>
<dependency>
<groupId>com.opencsv</groupId>
<artifactId>opencsv</artifactId>
<version>5.3</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.rabbitmq/amqp-client -->
<dependency>
<groupId>com.rabbitmq</groupId>
<artifactId>amqp-client</artifactId>
<version>5.14.2</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>31.1-jre</version>
</dependency>
<dependency>
<groupId>io.appium</groupId>
<artifactId>java-client</artifactId>
<version>8.1.1</version>
</dependency>
<dependency>
<groupId>io.github.bonigarcia</groupId>
<artifactId>webdrivermanager</artifactId>
<version>5.2.0</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>4.4.0</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
当我试图在一个新的项目上运行这个脚本时,这个依赖项是:
<dependency>
<groupId>io.appium</groupId>
<artifactId>java-client</artifactId>
<version>8.1.1</version>
</dependency>
它按预期工作,没有出错。我知道java客户端已经包含selenium-lib,但我试图删除它们,但它仍然存在错误。
我注意到:当我将除春季启动依赖项之外的所有依赖项添加到新鲜项目时,新鲜项目运行良好。但是当我添加spring和父项(spring-boot-starter-parent(的2个依赖项时,它失败了。所以我想这是一些关于spring依赖关系的东西,可能是特定于父依赖关系的。
我该如何解决?
环境-Mac、M1 pro、Intelij、Maven、Java 18
谢谢。
已解决
我发现<parent>
标记覆盖了依赖项(在我的例子中,"spring-boot-starter-parent"覆盖了Selenium-jars(所以我导航到~/.m2/repository.org/springframework/boot/spring-boot dependencies-2.6.3.pom更改了这些:<selenium.version>4.4.0<selenium.version><selenium htmlunit.version>2.64.0<selenium htmlunit.version>
事实上,我可以将我的spring boot更新到2.7.2,它应该也能正常工作。