首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >使用ATOMac进行Mac自动化测试

使用ATOMac进行Mac自动化测试

作者头像
周希
发布2020-07-27 16:36:51
2.1K0
发布2020-07-27 16:36:51
举报

ATOMac简介

atomac是一个支持在mac上做自动化的python库,GitHub地址如下:

https://github.com/pyatom/pyatom

安装

# Python2
sudo easy_install atomac

# Python3
pip3 install git+https://github.com/pyatom/pyatom/

使用

1. 启动程序

import atomac
atomac.launchAppByBundleId('com.apple.Automator')

查看bundleID的方法

在应用程序->右键选择包内容->Contents->Info.plist

2. 查看app信息

automator = atomac.getAppRefByBundleId('com.apple.Automator')
print(automator)

输出

<atomac.AXClasses.NativeUIElement AXApplication '自动操作'>

3. 获取应用标题

window = automator.windows()[0]
print(window.AXTitle)

输出

未命名

atomac支持获取和操作大部分的元素,可以使用xcode提供的accessibility inspector快速查看各个元素

路径: Xcode -> Open Developer Tools -> Accessibility inspector

4. 获取元素快照列表

window = automator.windows()[0]
sheet = window.sheets()[0]
print(sheet)

输出:

<atomac.AXClasses.NativeUIElement AXSheet '表单'>

windows是atomac的一种定位方法,用来获取window元素,这里我们获取到了最顶层窗口的元素,然后再用sheets定位方法来获取当前window的元素快照(sheet)

atomac所有的定位方法加上'R'字符,就变成了一个搜索方法(可以添加额外的搜索条件),例如上面的方法我们可以直接改为:

sheet = automator.sheetsR()[0]

5. 通过快照获取元素

通过快照我们可以进行元素定位, 这里我们以关闭按钮为例

closeButton = sheet.buttons('关闭')[0]
print(closeButton)

输出:

<atomac.AXClasses.NativeUIElement AXButton '关闭'>

支持的元素类型查询方法有:

textAreas
textFields
buttons
windows
sheets
staticTexts
genericElements
groups
radioButtons
popUpButtons
rows
sliders

6. 条件搜索元素

atomac支持findFirst方法,根据属性来进行元素搜索,例如

closeButton = sheet.findFirst(AXRole='AXButton', AXTitle='关闭')

支持的属性可以在Accessibility inspector中查看

findFirst和findFirstR方法返回首个匹配的元素, 如果没有找到匹配的元素则返回None

同时还有findAll和findAllR使用方法相同,返回所以匹配的元素列表,没有匹配的元素则返回空列表

7. 查看元素支持的属性

closeButton = sheet.findFirst(AXRole='AXButton', AXTitle='关闭')
print(closeButton.getAttributes())

输出

['AXRole', 'AXHelp', 'AXEnabled', 'AXWindow', 'AXSize', 'AXTitle', 'AXRoleDescription', 'AXTopLevelUIElement', 'AXFocused', 'AXParent', 'AXPosition', 'AXFrame', 'AXIdentifier']

查看属性值

print(closeButton.AXTitle)

输出

关闭

8. 查看元素支持的操作

print(closeButton.getActions())

输出

['Press']

9. 元素操作

closeButton.Press()

任何支持的操作都可以这样调用

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2020-07-27 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 安装
  • 使用
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档