使用appium为页面创建工厂时获取InstantiationException



我正在使用pagefactory方法运行一个测试用例,并创建了一个appium驱动程序。我正在尝试使用pagefactory类初始化页面,如下所示:

测试类别:

public class VerifyValidLogin {
@Test
public void CheckValidUser() throws MalformedURLException {
AppiumDriver driver = DeviceFactory.CreateDriver();
login login_page = PageFactory.initElements(driver, login.class);
}
}

DeviceFactory类别:

public class DeviceFactory {
public static AppiumDriver<MobileElement> driver;
public static AppiumDriver CreateDriver() throws MalformedURLException {
DesiredCapabilities cap = new DesiredCapabilities();
cap.setCapability( capabilityName: 'deviceName', value: 'Something');
...
URL url = new URL("http://127.0.0.1:4723/wd/hub");
driver = new AppiumDriver<MobileElement>(url,cap);
System.out.print("Application started");
return driver;
}
}

登录类具有元素定位器:

public class login {
AppiumDriver driver;
public login(AppiumDriver ldriver)
{
this.driver=ldriver;
}
@FindBy(how = How.XPATH,using ="xpath");
MobileElement SignInButton;
}

但我不确定我哪里做错了。

错误为

java.lang.RuntimeException: java.lang.InstantiationException: com.Demo.pages.login
at org.openqa.selenium.support.PageFactory.instantiatePage(PageFactory.java:134)
at org.openqa.selenium.support.PageFactory.initElements(PageFactory.java:64)
at com.Demo.Testcases.VerifyValidLogin.CheckValidUser(VerifyValidLogin.java:18)
...

我是自动化测试的新手,所以我无法正确理解错误。如果你需要更多细节,请告诉我。

初始化构造函数中的元素

public login(AppiumDriver ldriver)
{
this.driver=ldriver;
PageFactory.initElements(ldriver,this);
}

最新更新