appium / java-client

Java language binding for writing Appium Tests, conforms to W3C WebDriver Protocol
Apache License 2.0
1.21k stars 756 forks source link

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

Closed omprakashchavan01 closed 3 months ago

omprakashchavan01 commented 2 years ago

@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 commented 2 years ago

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

omprakashchavan01 commented 2 years ago

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

TyCmd commented 2 years ago

I am having the same issue

w1sp3r commented 2 years ago

I am having the same issue also.

amitkshatriya01 commented 2 years ago

Is there a workaround for this?

lilkimo commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

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

cameronbrandcoders commented 2 years ago

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 commented 2 years ago

@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 commented 2 years ago

@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 commented 2 years ago

@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 commented 2 years ago

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 commented 1 year ago

@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 commented 1 year ago

@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 commented 1 year ago

@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 commented 1 year ago

@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

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 commented 1 year ago

@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 commented 1 year ago

@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 commented 1 year ago

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

Hungleminh commented 1 year ago

@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 commented 1 year ago

@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 commented 1 year ago

@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 commented 1 year ago

@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 commented 1 year ago

@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 commented 1 year ago

@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 commented 1 year ago

Which testing framework are you working with then??

Hungleminh commented 1 year ago

Which testing framework are you working with then??

Appium, java gauge, java

taimoor8152 commented 1 year ago

@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 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

@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 commented 1 year ago

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

BraveEvidence commented 1 year ago

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 commented 3 months ago

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.