惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

酷 壳 – CoolShell
酷 壳 – CoolShell
H
Hacker News: Front Page
P
Palo Alto Networks Blog
T
ThreatConnect
Apple Machine Learning Research
Apple Machine Learning Research
博客园_首页
T
True Tiger Recordings
P
Privacy & Cybersecurity Law Blog
B
Blog
IT之家
IT之家
Last Week in AI
Last Week in AI
F
Full Disclosure
Hacker News: Ask HN
Hacker News: Ask HN
C
Comments on: Blog
Microsoft Azure Blog
Microsoft Azure Blog
C
Cybersecurity and Infrastructure Security Agency CISA
Microsoft Security Blog
Microsoft Security Blog
博客园 - 【当耐特】
N
News and Events Feed by Topic
NISL@THU
NISL@THU
腾讯CDC
雷峰网
雷峰网
Security Latest
Security Latest
李成银的技术随笔
M
Microsoft Research Blog - Microsoft Research
L
LangChain Blog
L
Lohrmann on Cybersecurity
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
C
Check Point Blog
Y
Y Combinator Blog
Recent Announcements
Recent Announcements
博客园 - Franky
N
News | PayPal Newsroom
V
V2EX
A
About on SuperTechFans
The Register - Security
The Register - Security
月光博客
月光博客
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Google Online Security Blog
Google Online Security Blog
MyScale Blog
MyScale Blog
Cisco Talos Blog
Cisco Talos Blog
Vercel News
Vercel News
WordPress大学
WordPress大学
C
Cyber Attacks, Cyber Crime and Cyber Security
The Hacker News
The Hacker News
IntelliJ IDEA : IntelliJ IDEA – the Leading IDE for Professional Development in Java and Kotlin | The JetBrains Blog
IntelliJ IDEA : IntelliJ IDEA – the Leading IDE for Professional Development in Java and Kotlin | The JetBrains Blog
爱范儿
爱范儿
A
Arctic Wolf
L
LINUX DO - 最新话题
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More

博客园 - 朱永光

Dapr云原生应用开发系列6:绑定构建块 Dapr云原生应用开发系列7:工作流集成 Dapr微服务应用开发系列5:发布订阅构建块 Dapr微服务应用开发系列4:状态管理构件块 Dapr微服务应用开发系列3:服务调用构件块 Dapr微服务应用开发系列2:Hello World与SDK初接触 Dapr微服务应用开发系列1:环境配置 Dapr微服务应用开发系列0:概述 利用Azure Functions和k8s构建Serverless计算平台 我如何通过K8S开发认证(CKAD)考试 Service Fabric是什么? 如何把遗留的Java应用托管在Service Fabric中 如何在本地数据中心安装Service Fabric for Windows集群 当TFS/VSTS遇上Power BI .NET英文技术文章导读(2017-03-23) .NET英文技术文章导读(2017-02-09) Power BI入门教程 数据分析师的福音——VS 2017带来一体化的数据分析开发环境 如何把Power BI嵌入到Web应用中
对Windows桌面应用程序进行UI自动化测试
朱永光 · 2019-08-23 · via 博客园 - 朱永光

题记:本文简述如何利用appium对Windows桌面应用程序进行UI自动化测试。

所谓UI自动化测试,就是模拟一个用户,对应用程序的UI进行操作,以完成特定场景的功能性集成测试。

要对Windows桌面应用程序进行UI自动化测试,目前可选的技术主要是两种:VS自带的CodedUI Test和Appium+WinAppDriver。但是,微软已经宣布VS2019将是带有CodedUI Test的最后一个版本,且在面对某些复杂场景的时候有点力不从心。而Appium作为移动应用主流的UI测试工具,已经被业界广泛采用,且相关的接口是标准化的,因此微软对其进行了扩展(即WinAppDriver),让Appium可以支持包括Universal Windows Platform (UWP), Windows Forms (WinForms), Windows Presentation Foundation (WPF), and Classic Windows (Win32)之内的Windows桌面应用。所以采用Appium来作为Windows桌面应用程序UI自动化测试的工具是最佳选择。

要完成UI自动化测试的大致步骤如下(你首先需要一台Windows 10的PC):

1,准备好待测试的Windows桌面应用程序。

2,到 https://github.com/Microsoft/WinAppDriver/releases 下载WinAppDriver的安装包,进行安装。并启用Windows 10的开发者模式。从安装目录(比如:C:\Program Files (x86)\Windows Application Driver)来启动WinAppDriver。

3,用你喜欢的测试框架创建UnitTest项目,在项目中引用Appium.WebDriver这个Nuget包。

4,编写测试用例,执行测试。

整个用例的编写也相对简单:

1,使用DesiredCapabilities来设定要测试的目标应用。

2,使用WindowsDriver<WindowsElement>来声明测试的会话。

3,通过测试会话查找对应的UI元素,对UI元素进行SendKeys(模拟填写内容)和Click(模拟点击)等操作,或者获取UI元素的相关Property和Attribute来进行验证。

4,编写测试最挑战的地方就是在于如何查找到UI元素,我们可以借用Windows SDK里面的inspect.exe这个工具来辅助我们查找。工具的位置在C:\Program Files (x86)\Windows Kits\10\bin里面的特定版文件夹中。用法是先启动应用程序并导航到待测试的界面,启动这个工具就会获得桌面上所有窗口的UI元素层级关系,并通过焦点等方式导航到要查找的UI元素上。查看相应的信息,并采用适合的查找方式。具体的查找方式可见:https://github.com/Microsoft/WinAppDriver#supported-locators-to-find-ui-elements。选择适合的查找方式有时候需要多尝试几种,有些UI元素只能用特定的方式来查找,比如html的input button只用FindElementByName ,而html的button就可以用FindElementByAccessibilityId 。

测试用例的编写可以参考WinAppDriver源代码自带的Sample,也可以参照我的示例:https://github.com/heavenwing/WindowsAppUITestSample

在我的这个示例当中,目标应用采用的是Hybrid方式运行(即通过WebBrowser来嵌入html,并用C#进行行为操作),考虑到这种应用程序可能是多个函数库组装在一起,所以测试项目理应也是多个项目组合的(即功能函数库对应一个测试项目),并且其他测试项目可以复用公共的测试步骤(比如:列表页面复用登录的测试步骤)。