最近在 windows 上做 UI 自动化,用的是 Windows UIA,用 python comtypes 库来访问 windows 的 COM 组件。写了一段时间脚本,感觉想要做好 UI 自动化是一个相当有难度的任务,尤其是对没有经验的团队。于是就有想法做一个 UI 自动化框架,来处理 UI 自动化中的一些常见的坑,简化

主要的想法就是:

根据这些想法我写了一个 python 的 UI 自动化框架 AXUI,实现了基本的想法,现在 windows 的支持比较完备,对 selenium 和 appium 的支持实现了基本功能,由于精力和工作环境,没有怎么测试。欢迎试用和拍砖,如果有人有兴趣一起完善就更好了。现在 AXUI 基本功能包括:

AXUI 的一些资源:

下面的介绍是 github 的介绍,平时工作中习惯用英文写文档,所以 AXUI 现在的文档也是英文的:

AXUI

Documentation Status
Code Health
Latest Version

AXUI is short for "Auto eXecute UI", is an UI automation framework, target to minimize the gap between tools and testers.
AXUI provides testers a powerful, unified, easy to use interface for common met platforms, like windows desktop, web, Android, IOS...

AXUI features

  1. AXUI provide a plug-in mechanism for automation guy to extend support for different UI
  2. AXUI provide built-in drivers for:
  1. AXUI provide an unified, easy to use python interface for use in test scripts
  2. AXUI separate UI logic from test scripts, make test scripts more readable and easier to maintain
  3. AXUI provide mechanism to handle auto met UI automation issues, like UI response time

An overview of AXUI structure

AXUI structure

code demonstrations

This code is in example/selenium, it's a simple example to demonstrate how AXUI separate UI logic from test script.

Though this example give us a impression that AXUI add extra complexities but doesn't improve code readability.
Image that an app contains a lot of UI Elements, and the search identifiers split into multiple test scripts, then AXUI can gather all UI identifiers into one appmap, and make your scripts clean to read and maintain.

Original:

import selenium.webdriver as webdriver

browser = webdriver.Chrome(executable_path = r"chromedriver.exe")
browser.get(r"http://www.bing.com")

searchEdit = browser.find_element_by_id("sb_form_q")
goButton = browser.find_element_by_id("sb_form_go")

searchEdit.send_keys("AXUI")
goButton.click()

AXUI AppMap*:

<AXUI:app_map xmlns:AXUI="AXUI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="AXUI AXUI_app_map.xsd">
    <AXUI:funcs>
        <AXUI:func name="go_to_bing" description="">
            <AXUI:step type="GUI" cmd='browser.BrowserPattern.get "http://www.bing.com"'/>
        </AXUI:func>
    </AXUI:funcs>

    <AXUI:UI_elements>
        <AXUI:Root_element name="browser" >
            <AXUI:UI_element name="searchEdit" identifier="id='sb_form_q'" start_func="go_to_bing"/>
            <AXUI:UI_element name="goButton" identifier="id='sb_form_go'" start_func="go_to_bing"/>
        </AXUI:Root_element>
    </AXUI:UI_elements>
</AXUI:app_map>

AXUI Code:

import AXUI

config_file = "selenium.cfg"
app_map = "www.bing.com.xml"

AXUI.Config(config_file)
appmap = AXUI.AppMap(app_map)

appmap.browser.start(browser_name="CHROME", executable_path = r"chromedriver.exe")

appmap.browser.searchEdit.Keyboard.input("AXUI")
appmap.browser.goButton.Mouse.left_click()

More details, please check AXUI documents

To have quick experience about AXUI, please check AXUI samples


↙↙↙阅读原文可查看相关链接,并与作者交流