Windows自动化框架实现(0) - 知识准备
(一)Windows GUI自动化测试常用工具
Tool |
Comment |
主要封装框架 |
AutoIT |
Win32应用 |
Windows API |
Pywinauto |
一个python库,PC端自动化工具 |
Windows API, UI Automation |
UI Automation |
PC端自动化工具 |
UI Automation, Windows API |
Sikuli |
图形自动化 |
|
Winum |
支持Windows应用程序自动化,基于selenium,但API不完整,不够成熟,支持mobile |
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…)
- 控件是自绘出来的,没有句柄的概念
(三)PC 端自动化测试使用到的 python 模块
1.主要有 pywinauto、win32gui、pyautogui,主要功能如下:
- pywinauto:主要使用到 Application 类,用于应用程序管理(打开与关闭应用等)、窗口管理(最小化、最大化、关闭窗口)
- pywin32:包含 win32gui、win32api、win32con 3个子模块,用于窗口管理(定位窗口、显示和关闭窗口、获取窗口位置等)
- pyautogui:屏幕控制(截屏等)、鼠标控制(移动鼠标、单击、双击、右击、拖拽等)、键盘控制(编辑、按键等)
2. uiautomation,中国人封装的一个库:
- 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框架。
(四)GUI定位元素工具
Inspect.exe (uia)
UISpy.exe
spy++.exe (win32)
ViewWizard
Swapy (可简单生成pywinauto代码)
(五)使用的自动化框架
1.自动化框架的选择
Python+Robotframework+UIwinauto(基于uiautomation和win32重新封装的对控件操作的方法库)+Sikuli
1.1安装必需的安装包:
Pip install pywin32
Pip install uiautomation
Pip install robotframework-SikuliLibrary
1.2 Red.xml里引入SikuliLibrary,uiautomation包
2.定位工具:Inspect
3.控件类型
参考链接: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 |
标识一个包含子对象的窗口框架。 |
4.Sikuli的使用方法:
- 以图片定位,截图放到指定目录下。 例如:Knox Messenger>Image
- 方法的参数为图片路径
(六)自已封装的库UIwinauto
现有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 … |
参考资料
- UI Automation中文官网:https://docs.microsoft.com/zh-cn/dotnet/framework/ui-automation/
- Python库方法查询:https://www.programcreek.com/python/
Windows自动化框架实现(0) - 知识准备相关推荐
- 安装 Windows 自动化 API 3.0 后,Visual Studio 2010 的运行速度更快
安装 Windows 自动化 API 3.0 后,Visual Studio 2010 的运行速度更快 本文适用于以下产品: Microsoft Visual Studio 2010 如果未安装 Wi ...
- 安装 Windows 自动化 API 3.0 时,visual Studio 2010 更快地运行
如果未安装 Windows 自动化 API 3.0,使用 Windows 自动化 api 的应用程序可以显著减少 Microsoft Visual Studio 智能感知性能. 例如,Windows ...
- Appium自动化框架从0到1之 公共方法的封装
在写测试用例的时候,最常用的就是方法的调用, 我们在这里,把公共方法封装到一个文件中, 这样以后需要使用,直接调用这个方法就可以了. 直接上代码: common_func.py # -*- codin ...
- Appium自动化框架从0到1之 测试用例封装
我们直接封装测试用例的 setU 和teardown 模块 以后每次执行测试用例,直接调用该方法就可以了 myunit.py # -*- coding: utf-8 -*- ""& ...
- AiBote 2022 新研发的自动化框架,支持 Android 和 Windows 系统。速度非常快
Ai-Bot 基于流行的 Node.js 和 JavaScript 语言 的一款新自动化框架,支持 Windows 和 Android 自动化. 1.Windows xpath 元素定位算法支持 支持 ...
- 手把手教你从0到1搭建web ui自动化框架(python3+selenium3+pytest)
-前期准备 -环境 -实战: 从0开始 前期准备 为更好的学习自动化框架搭建,你需要提前了解以下知识: python基础知识 pytest单元测试框架 PO模式 selenium使用 环境 本次我们自 ...
- Selenium4.0+Python手撸自动化框架系列之 Web元素等待方式介绍 与 封装
目录 前言 三种等待 一.线程等待 二.隐性等待 三.显性等待 封装 一.参数设计 二.函数名设计 三.封装代码设计 前言 web自动化测试,常常因为硬件配制,浏览器,网速等因素导致网页加载速度过慢, ...
- Windows C#自动化框架
毕业后,也跟随着大流奔着高上大的自动化而去,先是学习几个小时的QTP知道大体的流程后(QTP确实极其容易上手),立马着手写自动化脚本,折腾了2次公司软件Vke后,发现vbs的语言局限性太强,且布置QT ...
- CYQ.Data 数据框架 V4.0 开源版本发布(源码提供下载,秋色园V2.5版本标配框架)
说明的说明: 博客园团队两次移此文出首页,说 这篇文章不属于知识分享型文章,并且有广告嫌疑. 本文的确属于分享型文章,而且分享的知识点比其它文章都多很多,看看网友回复"谢谢分享"就 ...
最新文章
- 启动过程以及故障排除
- python判断数据类型type_Python 判断数据类型有type和isinstance
- 《Credit Risk Scorecard》第四章:Data Review and Project Parameters
- 平时学习中的拙作,希望交更多的朋友,希望得到更多的指导和交流
- 计算机原理之程序是怎么运行的
- python模块cv2人脸识别_Python基于Opencv来快速实现人脸识别过程详解(完整版)
- Ubuntu 下安装VNC server
- 吴恩达机器学习week2
- 验证码图片 java_验证码图片
- 三菱5uplc伺服电机指令_「242本」PLC模拟量教程,含西门子、三菱、施耐德、欧姆龙等...
- 常用的端口号(port number)
- 网友眼中的杭州IT公司排名
- 如何让微信官方给你加圣诞帽
- 修改HTK代码,让其支持中文
- DeePin系统安装jdk以及eclipse
- 弹窗代码大全window.open
- 【Linux】ubuntu16.04/18.04安装I219-V有线网卡驱动
- es6中的generator函数详解
- ar.js 追踪图片mark播放视频,并且根据是否识别控制视频播放操作
- 解题报告 (十四) 数位DP
热门文章
- PDB python调试
- 太可了,刷透这份“架构师养成手册”成就自己的架构之路
- 计算机科学游戏化,智慧教育学院(计算机科学与技术学院)“智慧讲堂”学术讲座系列第六十九讲 ——尚俊杰研究员《基于学习科学视角的游戏化学习研究》...
- conductor 系统任务
- android 输出分辨率6,Android4.0 输出分辨率改为1280*720后,出现Out of Memory
- 感动中国的老人和军人!视频:老人背满满麻袋饼干送战士 跪求将其收下
- [毕业设计]最新自动化专业毕设选题题目推荐
- 优化页面的方法——6种
- 请描写一段芭蕾女孩痛苦极限劈叉的故事
- Python学习:多态与封装