0

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);
        }
    }
}
public final class DriverManager {
    private static ThreadLocal<AppiumDriver<MobileElement>> driver = new ThreadLocal<AppiumDriver<MobileElement>>();
    
    public static AppiumDriver<MobileElement> getDriver() {
        return driver.get();
    }
    static void setDriver(AppiumDriver<MobileElement> driverRef) {
        driver.set(driverRef);
    }
}

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();
    }
}


I am 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.<init>(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

Nisha
  • 41
  • 3

2 Answers2

1

I was also facing this issue and I was able to resole using below steps

  1. Remove the constructor HomePage()

  2. Now in the class were you are calling your page object class there call it in below format.

    HomePage hommePagePO = PageFactory.intiElement(driver, HomePage.class);
    

For example: PageObject class:

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

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

Test Class:

  @BeforeClass
   public void setup(){
   // initialize your driver and then pass the driver
   
   HomePage homePagePO = PageFactory.initElements(driver, HomePage.class);
   }

Or

When you are creating your pageObject call constructor, call the initElement like given below:

PageObject class:

 public class HomePage{

    public Home(Appium driver){
    PageFactory.intiElement(driver, this.getClass());
    }
    @AndroidFindBy(xpath="//*[@content-desc='Accessibility']")
    private MobileElement eleAccessibility;
    Page
    public void clickAccessibility() {
    eleAccessibility.click();
    }
    }
Suhail Ahmed
  • 504
  • 1
  • 9
  • 19
  • Thanks Suhail. I was exhausted looking into other solution. This worked for me. Previously above code worked. Not sure why it is changed like this. – Gopinath V S Jan 12 '23 at 16:37
-1

facing the same issue while initializing page object model. no results found till now.

  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Feb 01 '22 at 07:49