环境
macOS:10.15.7 (19H512)
Python 3.6.3
简介
We are pleased to introduce the first Python library to fully enable GUI testing of Mac applications via
the Apple Accessibility API. This library was created out of desperation. Existing tools such as using
appscript to send messages to accessibility objects are painful to write and slow to use. ATOMac has
direct access to the API. It's fast and easy to use to write tests.
翻译:
基于python 的mac UI自动化工具
安装
pip3 install git+https://github.com/pyatom/pyatom/
- 安装时遇到报错
error: i386 (32-bit) is not supported by PyObjC
- 解决方案:降低了pyobjc版本
pip3 install -U pyobjc==6.2.2
使用
元素属性对应说明
ATOMac 库使用的元素属性均在其属性名(通过 Accessibility Inspector 查到)前面加 AX,且首字母大写,如下所示
ATOMac | Accessibility Inspector |
---|---|
AXRole | Role |
AXPosition | Position |
AXRoleDescription | Type |
AXValue | Value |
API
options | useage |
---|---|
getAttributes() | 获取元素所有属性 |
getActions() | 查看元素支持操作 |
window.tripleClickMouse(x + width / 2, y + height / 2) window.sendKeys('123') |
键盘输入 |
AXPosition | 坐标 |
window.clickMouseButtonLeft(x + width / 2, y + height / 2) | 左键单击 |
window.doubleClickMouse(x + width / 2, y + height / 2) | 双击 |
window.groups()[0] | 定位 |
输入键盘上的修饰符
sendKeys([RETURN])
key | 键盘修饰符 |
---|---|
TAB | '<tab>' |
RETURN | '<return>' |
SPACE | '<space>' |
ESCAPE | '<escape>' |
CAPS_LOCK | '<capslock>' |
DELETE | '<delete>' |
NUM_LOCK | '<num_lock>' |
SCROLL_LOCK | '<scroll_lock>' |
PAUSE | '<pause>' |
BACKSPACE | '<backspace>' |
INSERT | '<insert>' |
网友评论