我将此类作为页面对象:
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;
}
我将此类作为测试用例类:
public class LaunchPageTest extends Android {
@Test
public void Click_SigninNow() throws MalformedURLException {
LaunchPageObject lp = new LaunchPageObject(setDriver());
lp.Click_SigninNow();
}
}
我有此错误日志:
失败:立即点击登录 java.lang.ExceptionInInitializerError 在io.appium.java_client.pagefactory.utils.ProxyFactory.getEnhancedProxy(ProxyFactory.java:52) 在io.appium.java_client.pagefactory.utils.ProxyFactory.getEnhancedProxy(ProxyFactory.java:33) 在io.appium.java_client.pagefactory.AppiumFieldDecorator.proxyForAnElement(AppiumFieldDecorator.java:217) 在io.appium.java_client.pagefactory.AppiumFieldDecorator.access $ 0(AppiumFieldDecorator.java:215) 在io.appium.java_client.pagefactory.AppiumFieldDecorator $ 1.proxyForLocator(AppiumFieldDecorator.java:107) 在org.openqa.selenium.support.pagefactory.DefaultFieldDecorator.decorate(DefaultFieldDecorator.java:62) 在io.appium.java_client.pagefactory.AppiumFieldDecorator.decorate(AppiumFieldDecorator.java:155) 在org.openqa.selenium.support.PageFactory.proxyFields(PageFactory.java:113) 在org.openqa.selenium.support.PageFactory.initElements(PageFactory.java:105) 在POM.LaunchPageObject。(LaunchPageObject.java:35) 在TestCases.LaunchPageTest.Click_SigninNow(LaunchPageTest.java:17) 在sun.reflect.NativeMethodAccessorImpl.invoke0(本机方法)
该测试将打开该应用程序,但无法单击该元素。知道这里发生了什么吗?
答案 0 :(得分:2)
保留页面对象并测试以下类
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();
}
}