Python appium UI automation testing framework discussion

Table of contents

Foreword:

Framework commonality summary

Auto_Analysis permission pop-up recognition


Foreword:

 Python Appium UI automation testing framework is a tool for testing mobile applications that combines the features of Python programming language and Appium testing framework.

Framework commonality summary

1 Automatically find devices to connect to devices
2 Automatically start appium server
3 Use case framework unittest pytest
4 Use case organization yml read ini read excell or do html front-end writing
5 use case assert unittest assert or pytest or third-party asertpy
6 use case report format htmltestrunner Allure ExtentReports etc.
This is Auto_Analysis

7 Use case multi-thread running failure re-run mechanism
8 Android direction automatic monitoring permission pop-up window (macaca has the service parameter permissionPatterns implementation, appium can also, Auto_Analysis also implements a monitoring screen in public.installApp to see if there is an installation button that needs to be clicked)
9 Execution process exception capture and Log The log of Auto_Analysis log is very good, using logging.

10 Is the execution process performance capture in the form of adb or other forms such as gt introduced by atx or a professional appetizer tool.

A summary of some good framework ideas and open source implementations found in the above simple browsing of the forum, everyone's implementation and support are more or less different. I have adjusted all the open source ones, and after a general look, each has its own advantages and disadvantages.
Some things I want are in this frame, and some things I want to see are in another frame. In short, each project has its own advantages and disadvantages.

So I want to start a discussion post, all the python masters in the jar, you can come and discuss it together. What is mentioned in the general summary section, what is the best way to achieve it.

Auto_Analysis permission pop-up recognition


Auto_Analysis also implements a monitoring screen in the public.installApp to see if there is an install button that needs to be clicked. After debugging, I found that I
installed the apk of the demo in my Xiaomi mix2. I can’t click to continue the installation, so if you want to expand, you can use different systems. write here.
For example, Android's native version is com.android***, while Xiaomi's is com.miui***.

First capture the installation pop-up window of miui9.2 to see what it is


It turns out that package=com.miui.securitycenter resource-id=android:id/button2
sees that the continued installation conflicts with the button4 = 'android:id/button1' defined in the code, so it is rejected first every time (miui9. 2 reject is android:id/button1). . . . .

"""
同属性单个元素,返回单个坐标元组
button_list:常见的确认,同意,按钮控件id
"""
button0 = 'com.android.packageinstaller:id/ok_button'
button1 = 'com.android.packageinstaller:id/btn_allow_once'
button2 = 'com.android.packageinstaller:id/bottom_button_two'
button3 = 'com.android.packageinstaller:id/btn_continue_install'
#追加的miui9.2系统 继续安装的package=com.miui.securitycenter  resource-id=android:id/button2  
#这么写没过先放这儿 button4 = 'com.miui.securitycenter:id/android:id/button2'
#button4 = 'android:id/button1'与miui9.2 securitycenter权限安装 继续安装冲突 改为android:id/button2
button4 = 'android:id/button2'
button5 = 'vivo:id/vivo_adb_install_ok_button'
button_list = [button0, button1, button2, button3, button4, button5]

After the change, the permission installation pop-up window of miui9.2 is perfectly recognized

The principle of this method I saw is to grab the xml of the entire interface, similar to getpageresource in appium or appcrawler, and then parse the element xml to find the corresponding element to operate.
It is much better than other appium solutions for finding permission pop-up windows.

Attach the relevant code:

def main(self):
    """
    开启多线程:
            线程1:安装应用
            线程2:获取当前页面是否有可点击的按钮
    :return:
    """
    ini = U.ConfigIni()
    install_file = ini.get_ini('test_install_path', 'path')
    package_name = ini.get_ini('test_package_name', 'package_name')

    threads = []

    click_button = threading.Thread(target=self.tap_all, args=())
    threads.append(click_button)
    install_app = threading.Thread(
        target=self.__install_app, args=(
            package_name, install_file))
    threads.append(install_app)
    process_list = range(len(threads))

    for i in process_list:
        threads[i].start()
    for i in process_list:
        threads[i].join()

    self.adb.shell('"rm -r /data/local/tmp/*.xml"')


@U.l()
def __element(self):
    """
    同属性单个元素,返回单个坐标元组
    button_list:常见的确认,同意,按钮控件id
    """
    button0 = 'com.android.packageinstaller:id/ok_button'
    button1 = 'com.android.packageinstaller:id/btn_allow_once'
    button2 = 'com.android.packageinstaller:id/bottom_button_two'
    button3 = 'com.android.packageinstaller:id/btn_continue_install'
    #追加的miui9.2系统 继续安装的package=com.miui.securitycenter  resource-id=android:id/button2  button4 = 'com.miui.securitycenter:id/android:id/button2'
    #button4 = 'android:id/button1'与miui9.2 securitycenter权限安装 继续安装冲突 改为android:id/button2
    button4 = 'android:id/button2'
    button5 = 'vivo:id/vivo_adb_install_ok_button'
    button_list = [button0, button1, button2, button3, button4, button5]
    self.__uidump()
    self.pattern = re.compile(r"\d+")
    if not os.path.exists(self.all_result_path + "/dump.xml"):
        U.Logging.warn('Failed to get xml')
        return None

    tree = ET.ElementTree(file=self.all_result_path + "/dump.xml")
    tree_iter = tree.iter(tag="node")
    for elem in tree_iter:
        if elem.attrib["resource-id"] in button_list:
            bounds = elem.attrib["bounds"]
            coord = self.pattern.findall(bounds)
            x_point = (int(coord[2]) - int(coord[0])) / 2.0 + int(coord[0])
            y_point = (int(coord[3]) - int(coord[1])) / 2.0 + int(coord[1])
            return x_point, y_point
    else:
        return None

def tap(self):
    """
    点击动作
    :return:
    """
    coordinate_points = self.__element()
    if coordinate_points is not None:
        self.adb.touch_by_element(coordinate_points)

def tap_all(self):
    """
    不间断获取xml,并且点击。配合多线程使用
    :return:
    """
    while True:
        self.tap()
        if not self.queue.empty():
            break

When installing the APP, the main starts two threads. One installation is responsible for installing the apk, and the other is monitoring. First, it captures the element object tree xml of the current installation interface and then loops to determine whether there are elements in the __element definition. If so, click .

This solution is also bundled in the installation process, I still want that, whether it is in the installation process or in the process of running the process use case of the apk, it can capture inexplicably.

But this idea can be changed.

  As someone who has been here, I also hope that everyone will avoid some detours

Here I will share with you some necessities of the way forward in automated testing, hoping to help you.

(WEB automated testing, app automated testing, interface automated testing, continuous integration, automated test development, big factory interview questions, resume templates, etc.)

I believe it can make you better progress!

Click on the small card below

Guess you like

Origin blog.csdn.net/Free355/article/details/131722966