Appium - PageFactory initElements 不工作

Appium - PageFactory initElements is not working

我将此 Class 作为我的页面对象:

public class LaunchPageObject  {

private AppiumDriver<AndroidElement> driver;

public LaunchPageObject() {

}

public LaunchPageObject(AppiumDriver<AndroidElement> driver) {

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

public void Click_SigninNow() {

    lnk_SigninNow.click();
}

@AndroidFindBy(xpath="//android.widget.Button[@text='LOGIN WITH FACEBOOK']")
MobileElement btn_SignupWithEmail;

@AndroidFindBy(xpath="//android.widget.Button[@text='SIGN UP WITH EMAIL']")
MobileElement btn_LoginWithFacebook;

@AndroidFindBy(xpath="//android.widget.TextView[@text='Sign in now']")
MobileElement lnk_SigninNow;
}

我有这个 class 作为我的测试用例 class:

public class LaunchPageTest extends Android {

  @Test
  public void Click_SigninNow() throws MalformedURLException {

  LaunchPageObject lp = new LaunchPageObject(setDriver());
  lp.Click_SigninNow();
  }
}

我有这个错误日志:

FAILED: Click_SigninNow java.lang.ExceptionInInitializerError at io.appium.java_client.pagefactory.utils.ProxyFactory.getEnhancedProxy(ProxyFactory.java:52) at io.appium.java_client.pagefactory.utils.ProxyFactory.getEnhancedProxy(ProxyFactory.java:33) at io.appium.java_client.pagefactory.AppiumFieldDecorator.proxyForAnElement(AppiumFieldDecorator.java:217) at io.appium.java_client.pagefactory.AppiumFieldDecorator.access[=12=](AppiumFieldDecorator.java:215) at io.appium.java_client.pagefactory.AppiumFieldDecorator.proxyForLocator(AppiumFieldDecorator.java:107) at org.openqa.selenium.support.pagefactory.DefaultFieldDecorator.decorate(DefaultFieldDecorator.java:62) 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 POM.LaunchPageObject.(LaunchPageObject.java:35) at TestCases.LaunchPageTest.Click_SigninNow(LaunchPageTest.java:17) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

测试打开应用程序但无法单击元素。知道这里发生了什么吗?

保留您的页面对象并像下面那样测试 类

public class LaunchPageObject {

    @AndroidFindBy(xpath="//android.widget.Button[@text='LOGIN WITH FACEBOOK']")
    MobileElement btn_SignupWithEmail;

    @AndroidFindBy(xpath="//android.widget.Button[@text='SIGN UP WITH EMAIL']")
    MobileElement btn_LoginWithFacebook;

    @AndroidFindBy(xpath="//android.widget.TextView[@text='Sign in now']")
    MobileElement lnk_SigninNow;

    public void click_SigninNow() {
        lnk_SigninNow.click();
    }

}




public class LaunchPageTest extends Android {

  LaunchPageObject lp       = PageFactory.initElements(getDriver(), LaunchPageObject.class);

  @Test
  public void Click_SigninNow() throws MalformedURLException {
    lp.Click_SigninNow();
  }

}