UI自动化是一个ROI较低的测试项(ROI即return on investment,中文意思是投资回报率)。但UI自动化相比接口自动化、白盒测试等,它更贴近手工业务测试行为。对于刚起步效率提升的团队来说,是最迅速的切入点,也是广大黑盒tester,提升自身技术能力的起跑线。
1. Win32 API(backend =’win32’)
MFC,VB6,VCL简单的WinForms控件和大多数旧的应用程序
2. MS UI Automation API(backend =’uia’)
WinForms,WPF, Store apps,Qt5, IE…(Metro App…)
- 控件是自绘出来的,没有句柄的概念
-
pywinauto
:主要使用到 Application 类,用于应用程序管理(打开与关闭应用等)、窗口管理(最小化、最大化、关闭窗口)
-
pywin32
:包含 win32gui、win32api、win32con 3个子模块,用于窗口管理(定位窗口、显示和关闭窗口、获取窗口位置等)
-
pyautogui
:屏幕控制(截屏等)、鼠标控制(移动鼠标、单击、双击、右击、拖拽等)、键盘控制(编辑、按键等)
-
uiautomation
:
用
Python
和
C++
对
UIAutomation
做了一层封装,通过句柄,坐标位置对应用进行操作
https://docs.microsoft.com/en-us/dotnet/framework/ui-automation/ui-automation-overview?redirectedfrom=MSDN
比如python的两个模块pywinauto和uiautomation,但是pywinauto主要是封装Win32的api,只局限于winform框架,而python中的uiautomation其实是封装的windows中的uia框架。
Swapy (
可简单生成pywinauto代码)
Python+Robotframework+UIwinauto(基于uiautomation和win32重新封装的对控件操作的方法库)+Sikuli
1.1安装必需的安装包:
Pip install pywin32
Pip install uiautomation
Pip install robotframework-SikuliLibrary
1.2 Red.xml里引入SikuliLibrary,uiautomation包
参考链接:
https://docs.microsoft.com/zh-cn/dotnet/framework/ui-automation/ui-automation-control-types
ControlType 类包含以下控件类型:
Button
|
标识一个按钮控件。Identifies a button control.
|
Calendar
|
标识一个日历控件,例如日期选取器。Identifies a calendar control, such as a date-picker.
|
CheckBox
|
标识一个复选框控件。Identifies a check box control.
|
ComboBox
|
标识一个组合框控件。Identifies a combo box control.
|
Custom
|
标识一个控件,该控件不属于已定义的控件类型之一。Identifies a control that is not one of the defined control types.
|
DataGrid
|
标识一个数据网格控件。Identifies a data grid control.
|
DataItem
|
标识一个数据项控件。Identifies a data item control.
|
Document
|
标识一个文档控件。Identifies a document control.
|
Edit
|
标识一个编辑控件,例如一个文本框。Identifies an edit control, such as a text box.
|
Group
|
标识一个充当其他控件的容器的组控件。Identifies a group control, which acts as a container for other controls.
|
Header
|
标识一个标题控件,它是一个用作信息的行和列标签的容器。Identifies a header control, which is a container for the labels of rows and columns of information.
|
HeaderItem
|
标识一个标题项,它是信息的行或列的标签。Identifies a header item, which is the label for a row or column of information.
|
Hyperlink
|
标识一个超链接控件。Identifies a hyperlink control.
|
Image
|
标识一个图像控件。Identifies an image control.
|
List
|
标识一个列表控件,例如列表框。Identifies a list control, such as a list box.
|
ListItem
|
标识一个列表项控件,它是列表控件的子项。Identifies a list item control, which is a child item of a list control.
|
Menu
|
标识一个菜单控件,例如应用程序窗口中的一个顶级菜单。Identifies a menu control, such as a top-level menu in an application window.
|
MenuBar
|
标识一个菜单栏控件,它通常包含一组顶级菜单。Identifies a menu bar control, which generally contains a set of top-level menus.
|
MenuItem
|
标识一个菜单项控件。Identifies a menu item control.
|
Pane
|
标识一个窗格控件。Identifies a pane control.
|
ProgressBar
|
标识一个进度条控件,该控件以可视方式指示一个长时间操作的进度。Identifies a progress bar control, which visually indicates the progress of a lengthy operation.
|
RadioButton
|
标识一个单选按钮控件,这种选择机制只允许在组中选择一项。Identifies a radio button control, which is a selection mechanism allowing exactly one selected item in a group.
|
ScrollBar
|
标识一个滚动条控件,例如应用程序窗口中的滚动条。Identifies a scroll bar control, such as a scroll bar in an application window.
|
Separator
|
标识一个分隔符,它在控件(例如菜单和工具栏)中创建一个可视的分隔。Identifies a separator, which creates a visual division in controls like menus and toolbars.
|
Slider
|
标识一个滑块控件。Identifies a slider control.
|
Spinner
|
标识一个微调控件。Identifies a spinner control.
|
SplitButton
|
标识一个拆分按钮,该按钮将执行默认操作,并且还可以扩展到其他可能操作的列表。Identifies a split button, which is a button that performs a default action and can also expand to a list of other possible actions.
|
StatusBar
|
标识一个状态栏控件。Identifies a status bar control.
|
Tab
|
标识一个选项卡控件。Identifies a tab control.
|
TabItem
|
标识一个选项卡项控件,它代表选项卡控件的一页。Identifies a tab item control, which represents a page of a tab control.
|
Table
|
标识一个表。Identifies a table.
|
Text
|
标识一个编辑控件,例如一个文本框或多格式文本框。Identifies an edit control, such as a text box or rich text box.
|
Thumb
|
标识滚动条中可拖到不同位置的控件。Identifies the control in a scrollbar that can be dragged to a different position.
|
TitleBar
|
标识窗口上的标题栏。Identifies the caption bar on a window.
|
ToolBar
|
标识一个工具栏,例如应用程序窗口中包含一组命令按钮的控件。Identifies a toolbar, such as the control that contains a set of command buttons in an application window.
|
ToolTip
|
标识一个工具提示控件,将指针移动到一个控件上方时或者有时使用键盘 Tab 键切换到一个控件时将出现此信息窗口。Identifies a tooltip control, an informational window that appears as a result of moving the pointer over a control or sometimes when tabbing to a control using the keyboard.
|
Tree
|
标识一个树控件。Identifies a tree control.
|
TreeItem
|
标识
TreeItem
控件中的一个节点。Identifies a node in a
TreeItem
control.
|
Window
|
标识一个包含子对象的窗口框架。
|
-
以图片定位,截图放到指定目录下。 例如:Knox Messenger>Image
-
方法的参数为图片路径
现有UIautomation库中的方法主要是根据句柄和位置操作元素,不利于代码的可移植和稳定性。
需要自己封装根据控件操作的元素的方法。
可用于查询元素的属性如下,使用关键字参数:**kw可匹配任意类型
ControlType: int, a value in class `ControlType`.
ClassName: str.
AutomationId: str.
Name: str.
SubName: str, a part str in Name.
RegexName: str, supports regex using re.match.
引用uiautomation: Click, Right Click, Send Keys, Get Ctrl…
引用win32gui: switch window
操作控件的UI automation方法参照:
https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nn-uiautomationclient-iuiautomationelement
Check Ctrl EnabledOrNot, Check Box Ticked Or Not, Check MsgofDupGrp
Verify Ctrl Exist, Verify Ctrl Display, Verify Ctrl IsEnabled, Verify Ctrl IsDisabled…
验证方法的选择:
1. 使用RF框架BuiltIn中的自带的验证方法
2. 使用RF框架asserts中的方法封装自有方法
3. 使用RF框架中的底层方法AssertionError封装自有方法
找到控件后直接调用uiautomation库中已有方法,不需要传句柄和位置参数,目前未完全封装验证方法,后续可自行封装。
Uiautomation>Control类下面主要包括:
各类型控件的具体方法参照各具体类
操作
|
属性
|
获取
|
判断
|
类型对象
|
Click
MiddleClick
RightClick
DoubleClick
WheelDown
WheelUp
MoveWindow
SendKey
SendKeys
SetFocus
|
IsEnabled
IsOffscreen
IsPassword
IsTopLevel
Name
AutomationId
ClassName
ControlType
ProcessId
|
GetPattern
GetChildren
GetAncestorControl
GetParentControl
|
Exist
Disappear
|
ButtonControl
EditControl
PaneContrl
MenuControl
…
|
(一)Windows GUI自动化测试常用工具 Tool Comment 主要封装框架 AutoIT Win32应用 Windows API Pywinauto 一个python库,PC端自动化工具 Windows API, UI Automation UI Automation ...
这里写自定义目录标题欢迎使用Markdown编辑器新的改变功能快捷键合理的创建标题,有助于目录的生成如何改变文本的样式插入链接与图片如何插入一段漂亮的代码片生成一个适合你的列表创建一个表格设定内容居中、居左、居右SmartyPants创建一个自定义列表如何创建一个注脚注释也是必不可少的KaTeX数学公式新的甘特图功能,丰富你的文章UML 图表FLowchart流程图导出与导入导出导入
欢迎使用Markdown编辑器
你好! 这是你第一次使用 Markdown编辑器 所展示的欢迎页。如果你想学习如何使用Mar
pywinauto 是一个能够用来模拟
Windows
GUI 操作的 Python 库。如果你在使用 pywinauto
自动化
操作的时候遇到了无法获取 DataGridView 类型控件的文本值的问题,你可以尝试以下几种方法来解决这个问题:
确保你已经正确地获取了 DataGridView 控件的引用。你可以使用 print() 函数打印出 DataGridView 控件的类型和名称,以确保...
在网上找 Python 客户端
自动化
测试的库,一般有pywinauto、pywin32、pyautogui、uiautomation。本文仅对 uiautomation 做简单的了解。
MS UI Automation 是 MSAA 技术的一个替代品:即让控件和应用程序具有更好的可达性(accessible)。MS UIA明确定义了两个role:UIA Provider 即软件本身,主要是软件的开发人员依据相应的模式去
实现
相关的 interface, UIA Client 即
自动化
脚本和相关的 assi.
PanelControl是一个控件容器;
通常将LayoutControl结合使用,LayoutControl可以在窗体变大或者变小时,使得LayoutControl的控件能同比变化;
LayoutControl中的Group可以将控件分组;
右键点击group控件选择Add Control可以添加相应的控件;
删除LayoutControl,因为一般我们通常...
实现
一个客户端的自动截图,然后自动上传客户端的截图到网站中。这里不是用浏览器打开的web 无法用 selenium 等web 端
自动化
工具来
实现
,只能用客户端
自动化
工具。
2 技术介绍
2.1 pywinauto
pywinauto是用到的主要python库 pywinauto中文文档
2.1.1 目前常用类似的python 客户端常用库
PyAutoGui - 一个流行的跨平台库(具有基于图像的搜索,没有基于文本的控件操作)。
Lackey - Sikuli的纯Python替代品(基于图像模式
这里写自定义目录标题引言win32gui功能快捷键合理的创建标题,有助于目录的生成如何改变文本的样式插入链接与图片如何插入一段漂亮的代码片生成一个适合你的列表创建一个表格设定内容居中、居左、居右SmartyPants创建一个自定义列表如何创建一个注脚注释也是必不可少的KaTeX数学公式新的甘特图功能,丰富你的文章UML 图表FLowchart流程图导出与导入导出导入
正在使用python进行
自动化
的编辑,这期间也是刚好测试了几个相关的软件:win32gui,pyautogui,pyautowin,发现