我正在使用Appium自动化Android应用程序,我有一个基础类与安装和拆除(在设置初始化appium会话和拆解销毁会话).
这个基类我继承了所有的testng类,现在为每个测试类Appium生成新的会话.
所以我的问题是,一旦为所有类生成,我们如何在所有类中维护appium会话.
谢谢
萨迪克
解决方法:
我使用Singlton设计模式实现了这种方法,这里的方法是:
public class SingltonFactory{
private static SingltonFactory instance = new SingltonFactory();
private static AppiumDriver<MobileElement> driver;
private SingltonFactory() {
}
// Get the only object available
public static SingltonFactory getInstance() {
return instance;
}
// Get the only object available
public void setDriver(AppiumDriver<MobileElement> driver1) {
driver = driver1;
}
public AppiumDriver<MobileElement> getAppiumDriver() {
return driver;
}
}
在之前的测试用例中添加初始化SingltonFactory并分配驱动程序对象,如下所示:
AppiumFactory appiumFactory = AppiumFactory.getInstance();
if(appiumFactory.getAppiumDriver() == null) {
driver = new AndroidDriver<MobileElement>(new URL("http://127.0.0.1:4723/wd/hub"), cap);
}
else{
driver = appiumFactory.getAppiumDriver();
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。