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

Unable to run the appium test with junit test runner using 2.0.0-beta.40 Appium Server

Open cnerkar1859 opened this issue 2 years ago • 8 comments

The problem

I ran into this issue recently where-in am trying to run my suite through test runner but unfortunately am getting java.lang.ExceptionInInitializerError, Instead i am able to run the individual feature file successfully one by one, I tried to downgrade appium server but didn't help, a similar issue has been raised by multiple people but not specific with the JUnit test runner ( https://github.com/appium/java-client/issues/1619 ), I am able to start the appium server but it fails at the

PageFactory.initElements(new AppiumFieldDecorator(driver), this); with java.lang.ExceptionInInitializerError

Environment

  • Appium version (or git revision) that exhibits the issue: 2.0.0-beta.40
  • Last Appium version that did not exhibit the issue - I don't remember I have tried with test runner before
  • Desktop OS/version used to run Appium: v1.22.3
  • Node.js version (unless using Appium.app|exe): v18.7.0
  • Npm or Yarn package manager: 8.15.0
  • Mobile platform/version under test: android ( same issue occurs on ios as well )
  • Real device or emulator/simulator: real device
  • Appium CLI or Appium.app|exe:

Details

I am able to run the individual cucumber features successfully but can't run only with the Junit test runner, I compared the capabilities as well but not sure what's wrong, I could really use expertise from this group to help me out on this issue, I am completely stuck at this moment.

Link to Appium logs

(https://gist.github.com/cnerkar1859/1eddb9ed212d3053839307525007f708)

Code To Reproduce Issue [ Good To Have ]

public class MyVfLoginPage {

public MyVfLoginPage(AppiumDriver driver) { this.driver = driver; PageFactory.initElements(new AppiumFieldDecorator(driver), this); // It's failing while iniatilising the elements }

@AndroidFindBy(xpath = "//*[@resource-id='signin_txtUsername']")
@iOSXCUITFindBy(id = "signin_txtUsername")
public WebElement txtUsername;

} }

NOTE - If I change the above code to
using PageFactory.initElements(driver, this); with @FindBy it goes through successfully

cnerkar1859 avatar Sep 06 '22 05:09 cnerkar1859

I have the same issue with java 17. Is there any solution to resolve it, so I can use both annotations AndroidFindBy and iOSXCUITFindBy? Appium: 2.0.0-beta.44 Appium Java client: 8.2.0

davudmurtazin avatar Sep 09 '22 10:09 davudmurtazin

@davudmurtazin: This is my observation, Initially --- I was on Appium Java client 8.0.0 with Java 8 and I was getting the above error, So I updated to java 11 with appium 8.2.0 and it worked, but also tried java 8 with 8.2.0 and it worked, So as per my analysis this won't be an issue with java, check if you have multiple java installed and try to keep only one and give a shot, not sure I caching creating some issue!

cnerkar1859 avatar Sep 15 '22 22:09 cnerkar1859

@cnerkar1859 No issues with java 15 and lower, but I have issues using PageFactory.initElements(driver, this); But if I turn to java 17, so getting java.lang.ExceptionInInitializerError in PageFactory.initElements(driver, this); Am I the only one with this issue?

davudmurtazin avatar Sep 16 '22 07:09 davudmurtazin

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

is there any solution for this issue everyone? I had the same case

Hungleminh avatar Oct 06 '22 04:10 Hungleminh

@Hungleminh - I believe we all are in the same boat, for me it's intermittent I am not able to find the root cause yet

cnerkar1859 avatar Oct 06 '22 04:10 cnerkar1859

one solution is to not use PageFactory at all and just use the old/classic POM as defined in Selenium.dev documentation

sinapot avatar Oct 06 '22 05:10 sinapot

one solution is to not use PageFactory at all and just use the old/classic POM as defined in Selenium.dev documentation

I need to use PageFactory to test on cross platform on Android and iOS. Is there any suitable solution to reduce as much as possible code to test on Android and iOS (compare to PageFactory)?

Hungleminh avatar Oct 06 '22 06:10 Hungleminh