我正在try 在一个Spring Boot项目上安装Appium--根据这里的https://github.com/appium/java-client/blob/master/docs/Installing-the-project.md

在运行简单脚本时,我收到以下错误:

线程"main"中出现异常java.lang.NoClassDefFoundError:org/Openqa/Selify/Internal/Required 在io.appium.java_client.remote.options.BaseOptions.setCapability(BaseOptions.java:144) 在io.appium.java_client.remote.options.CanSetCapability.amend(CanSetCapability.java:30) 在io.appium.java_client.remote.options.BaseOptions.setPlatformName(BaseOptions.java:86) 在io.appium.java_client.android.options.UiAutomator2Options.setCommonOptions(UiAutomator2Options.java:222) 在io.appium.java_client.android.options.UiAutomator2Options.(UiAutomator2Options.java:208) 在com.aniview.testService.content.initAppium.main(initAppium.java:25) 起因:java.lang.ClassNotFoundException:org.Openqa.selenium.inder.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个

我的 playbook :

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>

当我try 在一个新的项目上运行这个脚本时,只有这个依赖项:

  <dependency>
    <groupId>io.appium</groupId>
    <artifactId>java-client</artifactId>
    <version>8.1.1</version>
</dependency>

它像预期的那样工作,没有出错. 我知道Java-Client已经包含Selenium库,但我试图删除它们,但它仍然错误.

我注意到的是: 当我将我的所有依赖项添加到Fresh项目中时,除了Spring Boot依赖项之外,Fresh项目运行良好.但是,当我添加Spring的两个依赖项和父对象(Spring-boot-starter-parent)时,它失败了.所以我猜这与Spring依赖项有关,可能特定于父依赖项.

我怎么才能解决这个问题?

环境-Mac、M1 PRO、Intelij、Maven、Java 18

谢谢.

推荐答案

已解决

我发现<parent>个标记覆盖了依赖项(在我的例子中,"Spring-boot-starter-parent"覆盖了SeleniumJars) 所以我导航到了~/.m2/repository/org/springframework/boot/spring-boot-dependencies/2.6.3/spring-boot-dependencies-2.6.3.pom 更改了这些选项: <;selenium.version>;4.4.0<;/selenium.version>; <;selenium-htmlunit.version>;2.64.0<;/selenium-htmlunit.version>;

事实上,我可以将我的弹簧靴更新到2.7.2,它应该也可以工作.

Java相关问答推荐

更新我们的一个文物后出现了严重的符号引用错误

Javascript更新alert 可扩展内容样式与CSS—按钮更多/更少

Mat. n_Delete()和Mat. n_release的区别

Spring boot:Bean和动态扩展器

参数值[...]与预期类型java.util.Date不匹配

编译多个.Java文件并运行一个依赖于用户参数的文件

AssertJ Java:多条件断言

呈现文本和四舍五入矩形时出现的JavaFX窗格白色瑕疵

Java中将文本拆分为数字或十进制数字和字符串

在处理2个映射表时,没有更多的数据可从套接字读取

在Ubuntu 23.10上使用mp3创建JavaFX MediaPlayer时出错

无法使用Java PreparedStatement在SQLite中的日期之间获取结果

在使用具有不同成本的谓词调用allMatch之前对Java流进行排序会带来什么好处吗?

当我在Java中有一个Synchronized块来递增int时,必须声明一个变量Volatile吗?

在Java泛型中使用通配符时,如何推断类型

在Java中将.GRF转换为图像文件

Java泛型方法重载

java构造函数中的冻结操作何时发生?

在外部类和内部类之间,当调用外部类内部或外部的主方法时,它们的静态初始化程序的运行顺序不同

有没有办法仅将 JComboBox 中的选定项目居中(因此保持组合框中的所有项目左对齐)