如何在多个testng类之间保留Appium会话 [英] How to preserve Appium session between multiple testng class

查看:80
本文介绍了如何在多个testng类之间保留Appium会话的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Appium自动化Android应用程序,我有一个基本类与安装和拆除(在设置初始化appium会话和拆解销毁会话)。

I am automating Android application using Appium, I have One Base Class with Setup and Tear down (In setup initialization appium session and in teardown destroying session ).

此基类我在所有testng类中继承,现在为每个测试类Appium生成新会话。

This Base Class I inherited in all testng classes, now for each test class Appium new session generated.

所以我的问题是,一旦为任何一个类生成,我们如何在所有类中维护appium会话。

So My question is that How we maintain appium session through out the all class once it generate for any class.

谢谢
Sadik

Thanks Sadik

推荐答案

我已经实现了这个使用Singlton设计模式的方法是:

I have implemented this approach using Singlton design pattern here is approach:

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并分配如下的驱动程序对象:

Add initialize SingltonFactory in your before test cases and assign driver object like below:

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();
}

这篇关于如何在多个testng类之间保留Appium会话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆