python - 在 python 中识别 windows/linux GUI 中的文本以进行自动化测试

标签 python python-2.7 automated-tests ui-automation robotframework

我对自动化测试很陌生,有一些疑问。我需要自动化 Windows GUI。我已经使用 pyautogui 和 AutoIt 实现了按钮点击和打开文件。现在我有一项任务,因为我必须检测屏幕中的单词或正则表达式位置并单击它。python 中是否有任何工具或库可以实现这一点?我已经检查了以下项目:

  • 汽车
  • pyautogui
  • 西库里

此外,我不想使用 sikuli。还有其他可以与 Robot Framework 集成的 OCR 吗?

最佳答案

对于 Windows GUI,有强大的 Python 库 pywinauto (据我所知可以与 Robot Framework 集成)。它允许一些复杂的操作,例如 app.Dialog.TreeView.get_item(['1STLevel', '2ndlevel']).expand() 和通过正则表达式搜索控件:app.Dialog.child_window( title_re='^some text - .*$').click().

还有用于 pywinauto 的 GUI 帮助程序(和代码生成器)称为 SWAPY(它不是记录/重放支持,但非常有用)。我正在维护 pywinauto 项目。欢迎提出更详细的问题!

为了比较,有几个开源的 UI 自动化工具(按回答时的星数排序):

https://github.com/msanders/autopy/ (跨平台)

https://github.com/Lexikos/AutoHotkey_L/ (不是 Python,但很流行)

https://github.com/asweigart/pyautogui (跨平台)

https://github.com/pyatom/pyatom (MAC 操作系统)

https://github.com/ldtp/cobra (跨平台)

https://github.com/jacexh/pyautoit (AutoIt Python 界面)

https://github.com/xcgspring/AXUI

https://github.com/F1ashhimself/UISoup


编辑:所有已知桌面 GUI 自动化工具的评级每月都会在此处维护: https://github.com/pywinauto/pywinauto/wiki/UI-Automation-tools-ratings

关于python - 在 python 中识别 windows/linux GUI 中的文本以进行自动化测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32346472/

相关文章:

python - 覆盖 __import__ 后是否可以恢复?

c# - Atata - 如何使用 Atata 框架切换到新的浏览器窗口?

python - 将字符串转换为三引号字符串

python - 每个月的第 n 天运行 APScheduler 作业

python - 树的所有路径

python - 如果行中的任何值等于零,则在 pandas 数据框中删除行

python - 多个 python 安装和 pip,老兄,我的站 pip 包在哪里?

python - 如何在 pytest_bdd 的另一个功能文件实现中重用一个功能文件实现的步骤定义?

testing - 如何在 Coded UI 中阅读文本?

python - 如果 kwargs 中的键与函数关键字冲突怎么办