I have this Class as my page object:
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;
}
and I have this class as my test case class:
public class LaunchPageTest extends Android {
@Test
public void Click_SigninNow() throws MalformedURLException {
LaunchPageObject lp = new LaunchPageObject(setDriver());
lp.Click_SigninNow();
}
}
I have this error log:
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$0(AppiumFieldDecorator.java:215) at io.appium.java_client.pagefactory.AppiumFieldDecorator$1.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)
The test opens the app but is not able to click the element. Any idea what is happening here?
Keep your page object and test classes like below
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();
}
}