java-client icon indicating copy to clipboard operation
java-client copied to clipboard

[8.0.0 Beta 2] PageFactory still not working with Java 17

Open omprakashchavan01 opened this issue 3 years ago • 35 comments

@mykola-mokhnach @ayuryev

I tested 8.0.0 Beta 2 which has a fix for #1575 and I have got the same cglib error with Java JDK 17.0.1 which is the LTS.

Am I missing something here?

Please find the exception log below. I get this exception for Selenium's PageFactory.initElements(driver, this) command;

java.lang.ExceptionInInitializerError at io.appium.java_client.pagefactory.utils.ProxyFactory.getEnhancedProxy(ProxyFactory.java:53) at io.appium.java_client.pagefactory.utils.ProxyFactory.getEnhancedProxy(ProxyFactory.java:33) at io.appium.java_client.pagefactory.AppiumFieldDecorator.proxyForAnElement(AppiumFieldDecorator.java:209) at io.appium.java_client.pagefactory.AppiumFieldDecorator.access$000(AppiumFieldDecorator.java:61) at io.appium.java_client.pagefactory.AppiumFieldDecorator$1.proxyForLocator(AppiumFieldDecorator.java:100) at org.openqa.selenium.support.pagefactory.DefaultFieldDecorator.decorate(DefaultFieldDecorator.java:63) at io.appium.java_client.pagefactory.AppiumFieldDecorator.decorate(AppiumFieldDecorator.java:147) at org.openqa.selenium.support.PageFactory.proxyFields(PageFactory.java:111) at org.openqa.selenium.support.PageFactory.initElements(PageFactory.java:103) at base.BaseTest.(BaseTest.java:98) at pages.LoginPage.(LoginPage.java:9) at com.qa.tests.LoginTests.beforeMethod(LoginTests.java:48) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.base/java.lang.reflect.Method.invoke(Method.java:568) 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.internal.TestInvoker.runConfigMethods(TestInvoker.java:700) at org.testng.internal.TestInvoker.invokeMethod(TestInvoker.java:527) 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.access$000(SuiteRunner.java:28) at org.testng.SuiteRunner$SuiteWorker.run(SuiteRunner.java:418) at org.testng.internal.thread.ThreadUtil.lambda$execute$0(ThreadUtil.java:64) at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264) at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136) at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635) at java.base/java.lang.Thread.run(Thread.java:833) Caused by: net.sf.cglib.core.CodeGenerationException: java.lang.reflect.InaccessibleObjectException-->Unable to make protected final java.lang.Class java.lang.ClassLoader.defineClass(java.lang.String,byte[],int,int,java.security.ProtectionDomain) throws java.lang.ClassFormatError accessible: module java.base does not "opens java.lang" to unnamed module @6442b0a6 at net.sf.cglib.core.ReflectUtils.defineClass(ReflectUtils.java:464) at net.sf.cglib.core.AbstractClassGenerator.generate(AbstractClassGenerator.java:339) at net.sf.cglib.core.AbstractClassGenerator$ClassLoaderData$3.apply(AbstractClassGenerator.java:96) at net.sf.cglib.core.AbstractClassGenerator$ClassLoaderData$3.apply(AbstractClassGenerator.java:94) at net.sf.cglib.core.internal.LoadingCache$2.call(LoadingCache.java:54) at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264) at net.sf.cglib.core.internal.LoadingCache.createEntry(LoadingCache.java:61) at net.sf.cglib.core.internal.LoadingCache.get(LoadingCache.java:34) at net.sf.cglib.core.AbstractClassGenerator$ClassLoaderData.get(AbstractClassGenerator.java:119) at net.sf.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:294) at net.sf.cglib.core.KeyFactory$Generator.create(KeyFactory.java:221) at net.sf.cglib.core.KeyFactory.create(KeyFactory.java:174) at net.sf.cglib.core.KeyFactory.create(KeyFactory.java:153) at net.sf.cglib.proxy.Enhancer.(Enhancer.java:73) ... 39 more Caused by: java.lang.reflect.InaccessibleObjectException: Unable to make protected final java.lang.Class java.lang.ClassLoader.defineClass(java.lang.String,byte[],int,int,java.security.ProtectionDomain) throws java.lang.ClassFormatError accessible: module java.base does not "opens java.lang" to unnamed module @6442b0a6 at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:354) at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:297) at java.base/java.lang.reflect.Method.checkCanSetAccessible(Method.java:199) at java.base/java.lang.reflect.Method.setAccessible(Method.java:193) at net.sf.cglib.core.ReflectUtils$1.run(ReflectUtils.java:61) at java.base/java.security.AccessController.doPrivileged(AccessController.java:569) at net.sf.cglib.core.ReflectUtils.(ReflectUtils.java:52) at net.sf.cglib.core.KeyFactory$Generator.generateClass(KeyFactory.java:243) at net.sf.cglib.core.DefaultGeneratorStrategy.generate(DefaultGeneratorStrategy.java:25) at net.sf.cglib.core.AbstractClassGenerator.generate(AbstractClassGenerator.java:332) ... 51 more

omprakashchavan01 avatar Dec 26 '21 17:12 omprakashchavan01

I think it relates to https://github.com/cglib/cglib/issues/191

valfirst avatar Dec 27 '21 08:12 valfirst

@valfirst I'm under an impression that #1575 has fixed this issue. If not, I would appreciate if someone can confirm on this.

omprakashchavan01 avatar Dec 28 '21 11:12 omprakashchavan01

I am having the same issue

TyCmd avatar Dec 29 '21 21:12 TyCmd

I am having the same issue also.

w1sp3r avatar Jan 21 '22 15:01 w1sp3r

Is there a workaround for this?

amitkshatriya01 avatar Feb 25 '22 03:02 amitkshatriya01

same issue here in 8.0.0. I switched to jre 15.0.2 and all works, but i got this warn:

WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by net.sf.cglib.core.ReflectUtils$1 (file:/C:/Users/lilkimo/.m2/repository/cglib/cglib/3.3.0/cglib-3.3.0.jar) to method java.lang.ClassLoader.defineClass(java.lang.String,byte[],int,int,java.security.ProtectionDomain)
WARNING: Please consider reporting this to the maintainers of net.sf.cglib.core.ReflectUtils$1
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release

lilkimo avatar Mar 11 '22 05:03 lilkimo

I'm still facing the issue with java-client v8.0.0 Java - v15.0.2 Appium v1.22.2

It doesn't work and still same error as #1575

 Caused by: java.lang.RuntimeException: java.lang.NoSuchMethodException: jdk.proxy2.$Proxy119.proxyClassLookup() at io.appium.java_client.pagefactory.bys.builder.AppiumByBuilder.prepareAnnotationMethods(AppiumByBuilder.java:84)

MrRahulR avatar Mar 27 '22 20:03 MrRahulR

i have the same issue java-client : 8.1.1 java: 18.0.1 Appium : 2.0.0-beta.40

naveenv20 avatar Jul 31 '22 03:07 naveenv20

Running into the same issue java-client: 8.1.1 java: 18.0.2 appium: 1.22.3-4

Edit: I got it working, but I can't find any documentation on if this is how it is supposed to work now. If this is how the PageFactory is supposed to work, I have questions.

The old way of doing it is something like:

PageFactory.initElements(new AppiumFieldDecorator(driver), this);

@AndroidFindBy(id = "AndroidButtonID")
@iOSXCUITFindBy(id = "iOSButtonID")
public WebElement getButton;

The new way of doing it seems to be something like:

PageFactory.initElements(driver, this);

@FindBy(id = "ButtonID")
public WebElement getButton;

If this is indeed the new way to do this in Appium java-client 8 and java 18, this seems to remove the ability to have a FindBy for both Android and iOS populate the same WebElement variable name, depending on if I am testing iOS or Android.

cameronbrandcoders avatar Aug 08 '22 18:08 cameronbrandcoders

@cameronbrandcoders - In the above new way of doing how can we use the same WebElement for ios and android, the old way -

@AndroidFindBy(id = "AndroidButtonID") @iOSXCUITFindBy(id = "iOSButtonID") public WebElement getButton; do we have any solution?

@mykola-mokhnach - could you please help me on this issue, I am actually running in a loop and unable to find the root cause! Completely Stuck!

When I run the individual cucumber features, it works perfectly fine but when I try to run it through the test runner it throws the same error -

java.lang.ExceptionInInitializerError at io.appium.java_client.pagefactory.utils.ProxyFactory.getEnhancedProxy(ProxyFactory.java:53) at io.appium.java_client.pagefactory.utils.ProxyFactory.getEnhancedProxy(ProxyFactory.java:33) at io.appium.java_client.pagefactory.AppiumFieldDecorator.proxyForAnElement(AppiumFieldDecorator.java:209) at io.appium.java_client.pagefactory.AppiumFieldDecorator.access$000(AppiumFieldDecorator.java:61) at io.appium.java_client.pagefactory.AppiumFieldDecorator$1.proxyForLocator(AppiumFieldDecorator.java:100) at org.openqa.selenium.support.pagefactory.DefaultFieldDecorator.decorate(DefaultFieldDecorator.java:63) at io.appium.java_client.pagefactory.AppiumFieldDecorator.decorate(AppiumFieldDecorator.java:147) at org.openqa.selenium.support.PageFactory.proxyFields(PageFactory.java:110) at org.openqa.selenium.support.PageFactory.initElements(PageFactory.java:102)

Guys does anybody have a solution for the above issue?

appium java-client - 8.0.0 selenium java - 4.0.0-beta-4 Appium server - 2.0.0-beta.43 Java SDK - 8 Node - v18.7.0

cnerkar1859 avatar Sep 05 '22 02:09 cnerkar1859

@cnerkar1859 I have studied somewhere that you need to install the java version 11 ion order to resolve this issue. But unfortunately i am unable to resolve this issue.

taimoor8152 avatar Sep 16 '22 14:09 taimoor8152

@taimoor8152 This issue is resolved for me now , yes I also updated to JDK 11 and Appium Java Client to 8.2.0 & it worked,but I also gave a try on jdk 8 with appium 8.2.0 & it worked perfectly fine too, I haven’t tried on higher Java version greater than 11!

cnerkar1859 avatar Sep 16 '22 16:09 cnerkar1859

Im getting similar issue and in similar environment:

public BasePage(AppiumDriver appiumDriver){
    PageFactory.initElements(new AppiumFieldDecorator(appiumDriver), this);
    driver = appiumDriver;

Appium: 2.0.0-beta.44 JavaClient: 8.2.0 java 17.0.4.1 2022-08-18 LTS

error similar to reported above: java.lang.ExceptionInInitializerError at io.appium.java_client.pagefactory.utils.ProxyFactory.getEnhancedProxy(ProxyFactory.java:53) at io.appium.java_client.pagefactory.utils.ProxyFactory.getEnhancedProxy(ProxyFactory.java:33) at io.appium.java_client.pagefactory.AppiumFieldDecorator.proxyForAnElement(AppiumFieldDecorator.java:209) at io.appium.java_client.pagefactory.AppiumFieldDecorator.access$000(AppiumFieldDecorator.java:61) at io.appium.java_client.pagefactory.AppiumFieldDecorator$1.proxyForLocator(AppiumFieldDecorator.java:100) at org.openqa.selenium.support.pagefactory.DefaultFieldDecorator.decorate(DefaultFieldDecorator.java:63) at io.appium.java_client.pagefactory.AppiumFieldDecorator.decorate(AppiumFieldDecorator.java:147) at org.openqa.selenium.support.PageFactory.proxyFields(PageFactory.java:111) at org.openqa.selenium.support.PageFactory.initElements(PageFactory.java:103)

sinapot avatar Sep 24 '22 00:09 sinapot

@sinapot Please install java 11 first and this error will be removed automatically. If you are still facing any issue let me know.

taimoor8152 avatar Sep 26 '22 10:09 taimoor8152

@taimoor8152 @mykola-mokhnach java version: 11.0.11 javaClient: 8.2.0 selenium:4.4.0

@AndroidFindBy(id="yyy") @iOSXCUITFindBy(id="xxx") public WebElement backgroundImage;

By using @AndroidFindBy or @AndroidBy, the element identifier initialization is not happening. =>

org.openqa.selenium.NoSuchElementException: Can't locate an element by this strategy: by id or name "backgroundImage"

if i use @FindBy the element identifier is picked correctly. However, this restrict the execution in Android and iOS => org.openqa.selenium.NoSuchElementException: Can't locate an element by this strategy: By.id: yyy (failed the case to show how the identifier is picked)

benz-philip01 avatar Sep 27 '22 17:09 benz-philip01

@benz-philip01 Please install java 11.0 not 11.0.11.

If you are using eclipse in Mac Go to preferences -> java -> installed JREs (click on it) -> "check if java 11 path has been setup there Most probably the should look line this: /Library/Java/JavaVirtualMachines/jdk-11.jdk/Contents/Home

taimoor8152 avatar Sep 29 '22 11:09 taimoor8152

@taimoor8152 Not sure how to point java version specifically to 11.0. Installed java using homebrew. Even after pointing to 11.0, the java version is shown as 11.0.11

benzmathewphilip@Benzs-MacBook-Pro ~ % jenv versions system 1.8 1.8.0.292

  • 11.0 (set by /Users/benzmathewphilip/.jenv/version) 11.0.11 openjdk64-1.8.0.292 openjdk64-11.0.11

benzmathewphilip@Benzs-MacBook-Pro ~ % java -version openjdk version "11.0.11" 2021-04-20 OpenJDK Runtime Environment AdoptOpenJDK-11.0.11+9 (build 11.0.11+9) OpenJDK 64-Bit Server VM AdoptOpenJDK-11.0.11+9 (build 11.0.11+9, mixed mode)

benz-philip avatar Sep 29 '22 17:09 benz-philip

@benz-philip Can you please try to uninstall the java 11.0.11 then install java 11.0 again. it also works on java 8 if you are able to install it.

taimoor8152 avatar Sep 30 '22 08:09 taimoor8152

@benz-philip Can you please try to uninstall the java 11.0.11 then install java 11.0 again. it also works on java 8 if you are able to install it.

Thanks @taimoor8152 . Let me try

benz-philip avatar Sep 30 '22 15:09 benz-philip

@taimoor8152 - I remember posting here that it has resolved my issue but i have started seeing this issue again

cnerkar1859 avatar Oct 04 '22 03:10 cnerkar1859

@benz-philip Can you please try to uninstall the java 11.0.11 then install java 11.0 again. it also works on java 8 if you are able to install it.

Thanks @taimoor8152 . Let me try

I had the same issue as you. How was your issue going? Is it resolved?

Hungleminh avatar Oct 06 '22 01:10 Hungleminh

@benz-philip Can you please try to uninstall the java 11.0.11 then install java 11.0 again. it also works on java 8 if you are able to install it.

Can you share me why java 11? Is there any higher version of java if it works instead of java 11?

Hungleminh avatar Oct 06 '22 01:10 Hungleminh

@taimoor8152 - It started working for me again but for some reason, I had to stop the test runner in between & when I tried to run it again it started throwing the same error

cnerkar1859 avatar Oct 06 '22 03:10 cnerkar1859

@taimoor8152 - It started working for me again but for some reason, I had to stop the test runner in between & when I tried to run it again it started throwing the same error

Hi @taimoor8152, When i debug in to my script, it says null element, pls see below "testButton". Can you share your thought on that?

Screen Shot 2022-10-06 at 10 42 57 Screen Shot 2022-10-06 at 10 46 03 Screen Shot 2022-10-06 at 10 47 35

Hungleminh avatar Oct 06 '22 03:10 Hungleminh

@Hungleminh Can you please make -> java 8.1.1 -> Move selenium dependency to the the lates version i don't think its the lates version. -> Also please show me the testng version

taimoor8152 avatar Oct 06 '22 12:10 taimoor8152

@Hungleminh Can you please make -> java 8.1.1 -> Move selenium dependency to the the lates version i don't think its the lates version. -> Also please show me the testng version

I didnot use testng. Is there any related problem with that?

Hungleminh avatar Oct 06 '22 15:10 Hungleminh

Which testing framework are you working with then??

taimoor8152 avatar Oct 07 '22 10:10 taimoor8152

Which testing framework are you working with then??

Appium, java gauge, java

Hungleminh avatar Oct 07 '22 11:10 Hungleminh

@Hungleminh You need to do some work with testng as i am experienced with that only. I am not sure what your experience is but you i have worked with test ng

taimoor8152 avatar Oct 07 '22 11:10 taimoor8152

Was there ever an official fix for this? Or accepted workaround?

Also would like to know the “right” way to handle page factory classes for Appium purposes.

I’d love to define locators for Android and iOS in a single page class. But it seems that may be no longer supported?

james-vanhorn avatar Nov 02 '22 01:11 james-vanhorn