I'm trying to install appium on a Spring boot project - according to here https://github.com/appium/java-client/blob/master/docs/Installing-the-project.md
When running a simple script I got this ERROR:
Exception in thread "main" java.lang.NoClassDefFoundError: org/openqa/selenium/internal/Require at io.appium.java_client.remote.options.BaseOptions.setCapability(BaseOptions.java:144) at io.appium.java_client.remote.options.CanSetCapability.amend(CanSetCapability.java:30) at io.appium.java_client.remote.options.BaseOptions.setPlatformName(BaseOptions.java:86) at io.appium.java_client.android.options.UiAutomator2Options.setCommonOptions(UiAutomator2Options.java:222) at io.appium.java_client.android.options.UiAutomator2Options.(UiAutomator2Options.java:208) at com.aniview.testService.content.initAppium.main(initAppium.java:25) Caused by: java.lang.ClassNotFoundException: org.openqa.selenium.internal.Require at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641) at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188) at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521) ... 6 more
My script:
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");
}
}
My 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>
When I tried to run this script on a fresh new project just with this dependency:
<dependency>
<groupId>io.appium</groupId>
<artifactId>java-client</artifactId>
<version>8.1.1</version>
</dependency>
It worked as expected and didn't errored. I know that java-client contain already selenium libs but I tried to remove them and it still errors.
What I noticed is: When I adding all my dependencies to the fresh project EXCEPT the spring boot dependencies the fresh project works GOOD. BUT when i adding the 2 dependencies of spring and the parent (spring-boot-starter-parent) it FAILS. So I guess it's something with the spring dependencies maybe specific with the parent dependency.
How can I solve that ?
Environment - Mac, M1 pro, Intelij, Maven, Java 18
Thanks.
CodePudding user response:
SOLVED
I found out that <parent>
tag is overriding the dependencies (in my case "spring-boot-starter-parent" overrode Selenium jars)
So I navigated to ~/.m2/repository/org/springframework/boot/spring-boot-dependencies/2.6.3/spring-boot-dependencies-2.6.3.pom
changed those:
<selenium.version>4.4.0</selenium.version>
<selenium-htmlunit.version>2.64.0</selenium-htmlunit.version>
Actually I could update my spring-boot to 2.7.2 and it should work as well.