问题描述
我正在尝试通过 Appium 在 BrowserStack 上运行示例测试.所有代码都来自 BrowserStack 并使用他们的示例 .ipa 文件.以下是我收到的错误的日志.
I'm trying to run a sample test via Appium on BrowserStack. All the code comes from BrowserStack and uses their sample .ipa file. The following is the log for the error that I'm receiving.
Exception in thread "main" java.lang.NoClassDefFoundError: org/openqa/selenium/remote/internal/ApacheHttpClient$Factory
at io.appium.java_client.remote.AppiumCommandExecutor.<init>(AppiumCommandExecutor.java:55)
at io.appium.java_client.AppiumDriver.<init>(AppiumDriver.java:131)
at io.appium.java_client.ios.IOSDriver.<init>(IOSDriver.java:82)
at BrowserStackIOS.main(BrowserStackIOS.java:28)
Caused by: java.lang.ClassNotFoundException: org.openqa.selenium.remote.internal.ApacheHttpClient$Factory
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:583)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
... 4 more
这是在第 28 行引用的代码行
Here is the line of code that is being referenced at line 28
IOSDriver<IOSElement> driver = new IOSDriver<IOSElement>(new URL("http://"+userName+":"+accessKey+"@hub-cloud.browserstack.com/wd/hub"), caps);
除此之外,我正在使用 maven.我从 https://search.maven.org/search?q=g:io.appium%20AND%20a:java-client
In addition to that, I'm using maven.I got my dependencies from https://search.maven.org/search?q=g:io.appium%20AND%20a:java-client
来自 https://selenium.dev/downloads/
关于 Bindngs,我不确定我是否正确安装了它们.我解压缩了 zip 文件并将位于 libs 文件夹中的 .jar 文件添加到我的依赖项中.这是一个截图 https://prnt.sc/qoqwzf这是 selenium/remote/internal 文件夹的截图 https://prnt.sc/qoqxh8
Regarding the Bindngs, I'm not sure if I installed them correctly.I extracted the zip file and added the .jar files located in the libs folder to my dependencies.This is a screenshot https://prnt.sc/qoqwzfThis a screenshot of the selenium/remote/internal folder https://prnt.sc/qoqxh8
注意事项:以前从未使用过 maven,所以我只包括附加说明:当我运行 mvn install -U 时,我收到了构建成功当我尝试构建我的项目时,我只收到该错误.
Notes:Never used maven before so I'll just include additional notes:I receive a build success when I run mvn install -UI'm only receiving that error when I try to build my project.
我为尝试解决错误所做的工作:我已使用 https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java/4.0.0-alpha-4
What I've done to try and resolve the error:I've updated all selenium dependencies to 4.0.0-alpha-4 using https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java/4.0.0-alpha-4
我尝试通过以下方式编辑我的 pom.xml:添加网络驱动依赖
I tried editing my pom.xml by:Adding the web driver dependency
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-remote-driver</artifactId>
<version>4.0.0-alpha-4</version>
</dependency>
添加 Safari Web 驱动程序依赖
Adding the Safari web driver dependency
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-safari-driver</artifactId>
<version>4.0.0-alpha-4</version>
</dependency>
补充说明:我的 POM.xml 看起来与 https://search.maven.org/remotecontent?filepath=io/appium/java-client/7.3.0/java-client-7.3.0.pom一些额外的依赖项,我在上面已经提到过.
Additional notes:My POM.xml looks exactly like the one given in https://search.maven.org/remotecontent?filepath=io/appium/java-client/7.3.0/java-client-7.3.0.pom with a few additional dependencies, which I've noted above.
以下是我在主类中请求的导入
The following are the imports that I'm requesting in my main class
import java.net.URL;
import java.util.List;
import java.net.MalformedURLException;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.support.ui.ExpectedConditions;
import io.appium.java_client.MobileBy;
import io.appium.java_client.ios.IOSDriver;
import io.appium.java_client.ios.IOSElement;
我还根据我收到的错误将 maven 编译器源代码编辑为 7,因为编译器源代码 5 与我正在运行的内容不兼容.
I also edited the maven compiler source to 7 as per the error I was receiving requesting that I do so due to compiler source 5 being incompatible with what I was running.
<properties>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
</properties>
以下是我编辑过的 pom 的开头,不确定这是否是一个问题,但我想其他人会知道.
The following is the beginning of my pom, which I edited, not sure if this could be an issue or not but I figured someone else would know.
<modelVersion>4.0.0</modelVersion>
<groupId>-</groupId>
<artifactId>First</artifactId>
<version>1.0-SNAPSHOT</version>
<name>java-client</name>
<description>Java client for Appium Mobile Webdriver</description>
<url>http://appium.io</url>
如果需要任何其他信息,请告诉我.我目前正在调整我的环境,所以出现了各种错误并得到解决.这是唯一一个我一直无法真正理解的.
If any additional information is needed please let me know. I'm currently in the process of adjusting my environment so there have been various errors that have come up and gotten resolved.This is the only one I haven't been able to really get my head around.
我的 Appium 依赖项是
My Appium dependency is
<dependency>
<groupId>io.appium</groupId>
<artifactId>java-client</artifactId>
<version>4.1.2</version>
</dependency>
我当前的所有依赖
<dependencies>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>4.0.0-alpha-4</version>
<scope>compile</scope>
<exclusions>
<exclusion>
<artifactId>*</artifactId>
<groupId>com.google.code.gson</groupId>
</exclusion>
<exclusion>
<artifactId>htmlunit-driver</artifactId>
<groupId>*</groupId>
</exclusion>
<exclusion>
<artifactId>*</artifactId>
<groupId>net.sourceforge.htmlunit</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-support</artifactId>
<version>4.0.0-alpha-4</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-api</artifactId>
<version>4.0.0-alpha-4</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-safari-driver</artifactId>
<version>4.0.0-alpha-4</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-remote-driver</artifactId>
<version>4.0.0-alpha-4</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.5</version>
<scope>compile</scope>
</dependency>
已删除
org.apache.httpcomponentshttp客户端4.5.9编译已删除
<dependency>
<groupId>cglib</groupId>
<artifactId>cglib</artifactId>
<version>3.2.12</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>commons-validator</groupId>
<artifactId>commons-validator</artifactId>
<version>1.6</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.9</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.6</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>5.1.8.RELEASE</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>1.9.4</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.26</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>io.appium</groupId>
<artifactId>java-client</artifactId>
<version>4.1.2</version>
</dependency>
<!-- Thanks for using https://jar-download.com -->
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.10</version>
</dependency>
</dependencies>
推荐答案
这个问题的根本原因是 Jar地狱
Root cause of this problem is Jar hell
selenium 4.0.0-alpha-4 的依赖依赖于 Appium Java Client7.1.0.
由于您在 pom.xml 文件中声明的依赖项与 Appium Java 客户端的传递依赖项之间的冲突,您会收到错误消息.如果您将 Appium Java Client 4.1.2 更改为 Appium Java Client 7.1.0 将解决问题.
You're getting errors due to the conflict between dependencies you have declared in your pom.xml file and transitive dependencies of the Appium Java Client. If you will change Appium Java Client 4.1.2 to Appium Java Client 7.1.0 will solve the problem.
这篇关于ApacheHttpClient$Factory 抛出 java.lang.NoClassDefFoundError 异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!