AppiumFieldDecorator with POM gives error

I am trying to automate with Appium, TestNG and Maven. I am getting errors while initializing the page object model. An error log is attached with this. Tried many ways, but no luck. It would be great if anyone know where I am doing mistakes. java-client --> 6.1.0 testng --> 7.4.0

public final class Driver {
public static void initDriver() {
if (Objects.isNull(DriverManager.getDriver())) {
URL url = null;
try {
url = new URL(“http://127.0.0.1:4723/wd/hub”);
} catch (MalformedURLException e) {
e.printStackTrace();
}
DesiredCapabilities capability = new DesiredCapabilities();
capability.setCapability(MobileCapabilityType.PLATFORM_NAME, MobilePlatform.ANDROID);
capability.setCapability(“appPackage”, AppConstant.appPackage);
capability.setCapability(“appActivity”, AppConstant.appActivity);

        AppiumDriver<MobileElement> driver = new AppiumDriver<>(url, capability);
        DriverManager.setDriver(driver);
    }
}

}

DriverManager for parallel execution:

public final class DriverManager {
private static ThreadLocal<AppiumDriver> driver = new ThreadLocal<AppiumDriver>();

public static AppiumDriver<MobileElement> getDriver() {
    return driver.get();
}
static void setDriver(AppiumDriver<MobileElement> driverRef) {
    driver.set(driverRef);
}

}

POM:

public class HomePage{

@AndroidFindBy(xpath="//*[@content-desc='Accessibility']")
private MobileElement eleAccessibility;

public HomePage(){
    PageFactory.initElements(new AppiumFieldDecorator(DriverManager.getDriver(), Duration.ofSeconds(10)), this);}

public void clickAccessibility() {
    eleAccessibility.click();
}

}

Getting below Error:

java.lang.RuntimeException: java.lang.NoSuchMethodException: jdk.proxy2.$Proxy10.proxyClassLookup()
at io.appium.java_client.pagefactory.bys.builder.AppiumByBuilder.prepareAnnotationMethods(AppiumByBuilder.java:85)
at io.appium.java_client.pagefactory.bys.builder.AppiumByBuilder.getFilledValue(AppiumByBuilder.java:92)
at io.appium.java_client.pagefactory.bys.builder.AppiumByBuilder.createBy(AppiumByBuilder.java:148)
at io.appium.java_client.pagefactory.DefaultElementByBuilder.getBys(DefaultElementByBuilder.java:133)
at io.appium.java_client.pagefactory.DefaultElementByBuilder.buildMobileNativeBy(DefaultElementByBuilder.java:177)
at io.appium.java_client.pagefactory.DefaultElementByBuilder.buildBy(DefaultElementByBuilder.java:216)
at io.appium.java_client.pagefactory.AppiumElementLocatorFactory.createLocator(AppiumElementLocatorFactory.java:66)
at io.appium.java_client.pagefactory.AppiumElementLocatorFactory.createLocator(AppiumElementLocatorFactory.java:53)
at io.appium.java_client.pagefactory.AppiumElementLocatorFactory.createLocator(AppiumElementLocatorFactory.java:1)
at org.openqa.selenium.support.pagefactory.DefaultFieldDecorator.decorate(DefaultFieldDecorator.java:56)
at io.appium.java_client.pagefactory.AppiumFieldDecorator.decorate(AppiumFieldDecorator.java:155)
at org.openqa.selenium.support.PageFactory.proxyFields(PageFactory.java:113)
at org.openqa.selenium.support.PageFactory.initElements(PageFactory.java:105)
at com.pages.HomePage.(HomePage.java:23)
at com.testCases.TC001_AccessibilityTest.accessibilityTest(TC001_AccessibilityTest.java:14)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:78)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:567)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:133)
at org.testng.internal.TestInvoker.invokeMethod(TestInvoker.java:598)
at org.testng.internal.TestInvoker.invokeTestMethod(TestInvoker.java:173)
at org.testng.internal.MethodRunner.runInSequence(MethodRunner.java:46)
at org.testng.internal.TestInvoker$MethodInvocationAgent.invoke(TestInvoker.java:824)
at org.testng.internal.TestInvoker.invokeTestMethods(TestInvoker.java:146)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:146)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:128)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
at org.testng.TestRunner.privateRun(TestRunner.java:794)
at org.testng.TestRunner.run(TestRunner.java:596)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:377)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:371)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:332)
at org.testng.SuiteRunner.run(SuiteRunner.java:276)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:53)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:96)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1212)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1134)
at org.testng.TestNG.runSuites(TestNG.java:1063)
at org.testng.TestNG.run(TestNG.java:1031)
at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:115)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:77)
Caused by: java.lang.NoSuchMethodException: jdk.proxy2.$Proxy10.proxyClassLookup()
at java.base/java.lang.Class.getMethod(Class.java:2195)
at io.appium.java_client.pagefactory.bys.builder.AppiumByBuilder.prepareAnnotationMethods(AppiumByBuilder.java:83)
… 42 more

Your java version is ?

Result: xx
Expected: < 17 e.g. 11

@Aleksei Thank you for quick response.

My system I have Below installed versions:

C:/users < java -version
java version “11.0.13” 2021-10-19 LTS
Java™ SE Runtime Environment 18.9 (build 11.0.13+10-LTS-370)
Java HotSpot™ 64-Bit Server VM 18.9 (build 11.0.13+10-LTS-370, mixed mode)

Eclipse: Version: 2021-09 (4.21.0)

Appium-Server-GUI-windows-1.22.0

Maven dependancy:

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

	<!-- https://mvnrepository.com/artifact/org.testng/testng -->
	<dependency>
		<groupId>org.testng</groupId>
		<artifactId>testng</artifactId>
		<version>7.4.0</version>
	</dependency>

Initially, I started with Java 1.8 in my system, One of your post mentioned to have Java 11. So, yesterday I installed it. Not sure whether I need any extra configuration in Eclipse.

what selenium version you use? you should use selenium 3 with any java-client version < 8.0.X

Attaching my POM here. I have added the selenium dependency and getting different errors.

<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>
	<groupId>Appium-Selenium</groupId>
	<artifactId>Appium-Selenium</artifactId>
	<version>0.0.1-SNAPSHOT</version>

	<dependencies>

		<!-- Work With Appium -->
		<dependency>
			<groupId>io.appium</groupId>
			<artifactId>java-client</artifactId>
			<version>6.1.0</version>
		</dependency>

		<!-- https://mvnrepository.com/artifact/org.testng/testng -->
		<dependency>
			<groupId>org.testng</groupId>
			<artifactId>testng</artifactId>
			<version>7.4.0</version>
		</dependency>

		<dependency>
			<groupId>com.aventstack</groupId>
			<artifactId>extentreports</artifactId>
			<version>5.0.7</version>
		</dependency>

		<dependency>
			<groupId>org.seleniumhq.selenium</groupId>
			<artifactId>selenium-java</artifactId>
			<version>3.14.0</version>
		</dependency>
		<!-- Commons-IO contains utility classes, stream implementations, file 
			filters, and endian classes. -->
		<dependency>
			<groupId>commons-io</groupId>
			<artifactId>commons-io</artifactId>
			<version>2.8.0</version>
		</dependency>

		<!-- https://mvnrepository.com/artifact/org.apache.poi/poi -->
		<dependency>
			<groupId>org.apache.poi</groupId>
			<artifactId>poi</artifactId>
			<version>4.1.2</version>
		</dependency>

		<dependency>
			<groupId>org.slf4j</groupId>
			<artifactId>slf4j-log4j12</artifactId>
			<version>1.7.5</version>
		</dependency>

		<!-- For email -->
		<dependency>
			<groupId>javax.mail</groupId>
			<artifactId>mail</artifactId>
			<version>1.5.0-b01</version>
		</dependency>
		<!-- For email -->
		<dependency>
			<groupId>javax.activation</groupId>
			<artifactId>activation</artifactId>
			<version>1.1.1</version>
		</dependency>
		<dependency>
			<groupId>org.apache.commons</groupId>
			<artifactId>commons-email</artifactId>
			<version>1.5</version>
		</dependency>

	</dependencies>

	<build>
		<plugins>
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-surefire-plugin</artifactId>
				<version>3.0.0-M5</version>
				<configuration>
					<suiteXmlFiles>
						<suiteXmlFile>testng.xml</suiteXmlFile>
					</suiteXmlFiles>
				</configuration>
			</plugin>
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-compiler-plugin</artifactId>
				<configuration>
					<source>15</source>
					<target>15</target>
				</configuration>
			</plugin>
		</plugins>
	</build>

</project>

Getting below error:

java.lang.NoClassDefFoundError: org/openqa/selenium/logging/LoggingHandler
at com.driver.Driver.initDriver(Driver.java:47)
at com.testCases.BaseTest.invokeAppium(BaseTest.java:22)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:78)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:567)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:133)
at org.testng.internal.MethodInvocationHelper.invokeMethodConsideringTimeout(MethodInvocationHelper.java:62)
at org.testng.internal.ConfigInvoker.invokeConfigurationMethod(ConfigInvoker.java:385)
at org.testng.internal.ConfigInvoker.invokeConfigurations(ConfigInvoker.java:321)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:317)
at org.testng.SuiteRunner.run(SuiteRunner.java:276)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:53)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:96)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1212)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1134)
at org.testng.TestNG.runSuites(TestNG.java:1063)
at org.testng.TestNG.run(TestNG.java:1031)
at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:115)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:77)
Caused by: java.lang.ClassNotFoundException: org.openqa.selenium.logging.LoggingHandler
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:636)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:182)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:519)
… 21 more

How you start tests? IntelliJ or command line?

Hi @Aleksei, start executing by right click on the testng.xml file and running as a suite.

Initially I have not added the selenium dependancy except java-client and it was going at list till the test cases. However now it is not hitting the beforeSuite method itself.

with java-client 7.6.0 I do not use any selenium. i just mentioned it that with 8.0.X version you should user selenium 4.+ if you have it.
so remove from pom.
check in your IDE what Java version it users. e.g. mine in IntelliJ

Thank you @Aleksei, Please share which Intellij version are using? Let me try with Intellij…

I did not update it for quite time: 2021.2.2 mine.
And try run in command prompt / terminal also.

Thank you very much @Aleksei, I really appreciate for helping me with this problem.

I have installed IntelliJ with the same version which you mentioned and configured the same project and It is working fine. I fill might be some problem with the Eclipse ID version with this configuration.

Once again thank you very much.

Even i was facing same issue, i had java 18, I downgraded to java11

with java client

io.appium
java-client
7.6.0

I was able to resolve the issue

Thank you.