Aki - 跨平台PC端应用自动化测试框架

Apache License 2.0
Java
Windos/Mac
hank.huang · February 11, 2022 · 7310 次阅读 · 14 条评论

背景

Aki 是一个基于 Accessibility Api 实现的跨平台 (Mac/Windows)桌面端自动化测试框架,借助开源框架 JNA 实现了对系统底层 Api 的访问。

Maven 依赖

<dependency>
    <groupId>io.github.letmeno1</groupId>
    <artifactId>aki</artifactId>
    <version>1.0.3</version>
</dependency>

生成 Jar 包

mvn install

入门

需要 jdk version >= 1.8.0_295

对于 Mac

需要安装 Xcode
需要系统版本高于 10.6

需要在在隐私权限中开启 Xcode 对辅助设备访问的权限。系统偏好设置 > 安全性与隐私 > 通用访问 > 启用辅助设备访问。

对于 Windows

需要版本高于 Windows 7

元素定位工具

对于 Mac

Accessibility Inspector:Xcode -> 打开 Developer Tools

使用 “Accessibility Inspector” 可以查找到 App 对应的元素属性

对于 Windows

在主页里下载 inspect.exe

使用 “inspect.exe” 可以查找到 App 对应的元素属性

使用

启动应用程序并通过 identifier(Mac)或文件执行路径(Windows)初始化一个 UIElementRef 对象

对于 Mac: UIElementRef app = Operation.initializeAppRefForMac("com.apple.calculator");

对于 Windows: UIElementRef app = Operation.initializeAppRefForWin("C:\\WINDOWS\\System32\\calc.exe");

App 窗口本身就是一个 UIElementRef 对象,而每个元素也都是一个 UIElementRef 对象。你可以通过 UIElementRef 来调用各种查找或者是点击的方法

鼠标事件

UIElementRef 对象支持单击、双击、长按、悬停

例如: app.findElementsByText("Input phone number",0).click()app.findElementsByText("Input phone number",0).doubleClick()

输入事件

UIElementRef 对象支持输入和清除

例如: app.findElementsByText("Input phone number",0).type("188888")app.findElementsByText("Input phone number",0).clear()

查找元素

对于 Mac:

支持文本、role(元素类型)、identifier、xpath。

对于文本和 role,搜索到的元素会以列表的形式返回,调用时需要加入索引。

例如 app.findElementsByText("Input phone number",0)app.findElementsByRole("AXTextField",2)

1.通过文本

文本对应元素属性中的 “Title”、“Value” 和 “Help”

2.通过 Role

Role 对应元素属性中的 “Role”

3.通过 Xpath

这是一种通过元素的路径查找的方法 (待改进)

例如 app.findElementByXpath("AXStandardWindow/AXButton[1]")

4.通过 identifier

identifier 对应元素属性中的 “identifier”

例如 app.findElementByIdentifier("JoinButton")

对于 Windows:

支持 text(name)、role、automationId、fullDescription。

对于 text、role 和 fullDescription,搜索到的元素会以列表的形式返回,调用时需要加入索引。

例如app.findElementsByText("Input phone number",0)app.findElementsByRole("AXTextField",2)

1.通过文本

文本对应于元素属性中的 “Name”

2.通过 Role

Role 对应于元素属性中的 “Role”

例如 `app.findElementsByRole(app.findElementsByText("client",0))

4.通过 automationId

automationId 对应于元素属性中的"automationId"

例如 app.findElementByAutomationId ("num3button")

通用操作

支持鼠标事件、组合键盘事件、截图和结束进程

评论列表
hank.huang 发表于 November 08, 2023

@JIE 目前不支持

JIE 发表于 November 07, 2023

不能支持 linux 吗

章鱼 发表于 April 14, 2023

是的,试过各种最终还是用了图片识别的方案,哈哈

hank.huang 发表于 April 11, 2023

@miki 如果 window 上貌似对 webview 的控件也是支持的,Mac 不支持,如果一定要做,可以考虑图像识别

章鱼 发表于 April 06, 2023

想问下对于应用内置 webview,需要对 webview 控件进行 UI 操作的方案 有什么思路吗

hank.huang 发表于 February 20, 2023

@Testhuangzigang 可信度还是高的,而且可以根据你的需求做微调

Testhuangzigang 发表于 January 12, 2023

特征值识别可信度怎么样?对语 ui 是自渲染画图的应用支持度怎么样?最近搞非标的 windows 应用自动化头发都薅秃顶了

hank.huang 发表于 March 09, 2022

@cdtaogang 已经做了图像识别定位,对分别率无要求,随便的截图都可以

hank.huang 发表于 March 09, 2022
干饭狂人 发表于 March 04, 2022

项目地址呢?

陶刚 发表于 February 23, 2022

只能针对于可识别的标准控件,代码绘图界面直接拉胯

hank.huang 发表于 February 13, 2022

未来将支持各种语言

残月、 发表于 February 11, 2022

支持 python 调用嘛?

hank.huang 发表于 February 11, 2022

11