Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
omprakashchavan01 opened this issue Dec 26, 2021 · 37 comments
Closed

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

omprakashchavan01 opened this issue Dec 26, 2021 · 37 comments

Comments

@omprakashchavan01
Copy link

@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

@valfirst
Copy link
Collaborator

I think it relates to cglib/cglib#191

@omprakashchavan01
Copy link
Author

omprakashchavan01 commented Dec 28, 2021

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

@TyCmd
Copy link

TyCmd commented Dec 29, 2021

I am having the same issue

@w1sp3r
Copy link

w1sp3r commented Jan 21, 2022

I am having the same issue also.

@amitkshatriya01
Copy link

Is there a workaround for this?

@lilkimo
Copy link

lilkimo commented Mar 11, 2022

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

@MrRahulR
Copy link

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)

@naveenv20
Copy link

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

@cameronbrandcoders
Copy link

cameronbrandcoders commented Aug 8, 2022

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.

@cnerkar1859
Copy link

cnerkar1859 commented Sep 5, 2022

@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

@taimoor8152
Copy link

@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.

@cnerkar1859
Copy link

@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!

@sinapot
Copy link

sinapot commented Sep 24, 2022

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)

@taimoor8152
Copy link

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

@benz-philip01
Copy link

@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)

@taimoor8152
Copy link

@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

@benz-philip
Copy link

@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)

@taimoor8152
Copy link

@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.

@benz-philip
Copy link

@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

@cnerkar1859
Copy link

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

@Hungleminh
Copy link

@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
Copy link

@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?

@cnerkar1859
Copy link

@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

@Hungleminh
Copy link

@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

@taimoor8152
Copy link

@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

@Hungleminh
Copy link

@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?

@taimoor8152
Copy link

Which testing framework are you working with then??

@Hungleminh
Copy link

Which testing framework are you working with then??

Appium, java gauge, java

@taimoor8152
Copy link

@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

@james-vanhorn
Copy link

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?

@vicky-iv
Copy link

The decision for Java 17:
[pom.xml]:

  <properties>
     <jvm.options>--add-opens java.base/java.lang=ALL-UNNAMED</jvm.options>
    </properties>

  <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>3.0.0-M5</version>
                <configuration>
                    <argLine>${jvm.options}</argLine>
                </configuration>
            </plugin>
        </plugins>
    </build>

@nirtal85
Copy link

wrote a blog post on how to resolve this issue:
https://www.linkedin.com/pulse/solving-jdk-17-compatibility-issue-appium-step-by-step-nir-tal/

@ZuhayrMerchant
Copy link

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

Hi I am still getting the same issue in
JDK 19
selenium-java 4.8.1
appium java client 8.3.0

@vadik24
Copy link

vadik24 commented Feb 22, 2023

I'm also stuck with this issue on APPIUM 2.0 and JDK18. For now on, best solution is use @FindALL/@findby

@BraveEvidence
Copy link

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.

Thank you God

@Umeshahn
Copy link

Hi All, if still anyone facing same issue where Page Factory is not identifying the mobile elements. I have found that solution for that issue, please use as below and let me know if this works.

Compatibility Version:
Java JDK version - 17
Appium Version - 2.2.2
Java-client version - 9.0.0
Selenium version - 4.15.0

Sample Code:

@FindBy(id = "CompanySelectionTitleLabel")
@iOSXCUITFindBy(accessibility = "CompanySelectionTitleLabel")
WebElement companyDetailsLabel;

**Here**, @FindBy annotation used for Android Element
@iOSXCUITFindBy annotation used for IOS Element.

**Below is the Page Factory code:**
PageFactory.initElements(new AppiumFieldDecorator(driver, Duration.ofSeconds(10)),this);

So far, I am able to identify both android and iOS elements and working fine for me with above combination.

Please let me know if this works.

@alexandlazaris
Copy link

FYI I also came across this issue recently. I couldn't find any suitable documentation relating to this change and I was at wits end. Turns out, after lots of trial & error, you can do the following:

@FindAll({
        @FindBy(id = "//*[@resource-id='com.example:id/primaryButton']"), // Android
        @FindBy(id = "nextBtn")  // iOS
    })

The 'thing' though I'm seeing is that appium still looks for both platform locators even if you're running on 1 platform. Which mainly means the test takes longer and your duration will be impacted. I haven't used this method too much but will be keen to see others thoughts in future.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests