UI Automation JavaScript Reference
Use the UI Automation JavaScript library to write test scripts that exercise your app’s user interface elements while the app runs on a connected device. You write the tests in JavaScript, calling the UI Automation API to simulate user interaction. The system returns log information to the host computer.
Note: UI Automation simulates all user interface actions initiated by the script. For the sake of brevity and clarity, this document describes those actions in terms of a user’s perspective.
Accessing and Using User Interface Elements
In essence, your test script is an ordered set of commands, each of which accesses a user interface element in your app to perform a user action on it or to use the information associated within it. All the user interface elements in your app are represented to the script through an ordered hierarchy of objects defined by the UIAElements
class and its subclasses. To reach a specified UI element, the script simply calls down the element hierarchy, starting with the top-level target object obtained by calling UIATarget.localTarget()
. For example, the first button in the main window of your app might be referenced by index as follows:
UIATarget.localTarget().frontMostApp().mainWindow().buttons()[0]
If that first button is identified in your code as the Edit button, the following would also work:
UIATarget.localTarget().frontMostApp().mainWindow().buttons()["Edit"]
To tap that button, then, the script could use any of these three formats:
-
UIATarget.localTarget().frontMostApp().mainWindow().buttons()[0].tap();
-
UIATarget.localTarget().frontMostApp().mainWindow().buttons()["Edit"].tap();
-
var editButton=UIATarget.localTarget().frontMostApp().mainWindow().buttons()[0];
editButton.tap();
The Automation instrument maintains a complete element hierarchy that represents your app’s user interface. To view that hierarchy, use the logElementTree
method to write an outline of it to the log:
UIATarget.localTarget().frontMostApp().logElementTree()
Recording Results With the Log
To record data during its tests, the script uses UIALogger
class methods to send messages to the Automation instrument running on the host computer. Various methods are available to assist in organizing and analyzing the recorded data. For example:
-
To indicate the initiation of a specified test, use the
logStart
method:-
UIALogger.logStart("Test1");
-
-
To end a test and mark it as failed, use the
logFail
method:-
UIALogger.logFail("Failed to foo.");
-
-
To send a general-purpose debug message, use the
logDebug
method:-
UIALogger.logDebug("Done with level 3.");
-
You view the collected data in the Detail pane of the Automation instrument using Instruments.
Handling Alerts
When UI Automation encounters an alert during the execution of your script, it calls your alert handler, passing a reference to the UIAAlert
object representing the alert. Your script should handle the alert appropriately and return a value of true
, upon which normal script execution continues.
To ensure that alerts don't interfere with testing, the Automation instrument also implements a simple default alert handler. If your script’s alert handler returns false
, this default handler attempts to dismiss the alert by tapping the cancel button, if it exists; otherwise, it taps the default button.
The following code implements a simple alert handler that records a message to the log and returns false
, thereby depending on the default handler to dismiss the alert:
UIATarget.onAlert = function onAlert(alert) { |
var title = alert.name(); |
// add a warning to the log for each alert encountered |
UIALogger.logWarning("Alert with title '" + title + "' encountered!"); |
UIATarget.localTarget().captureScreenWithName("alert_" + (new Date()).UTC()); |
// test if your script should handle the alert, and if so, return true |
// otherwise, return false to use the default handler |
return false; |
} |
相关推荐
C# UIAutomation C# UIAutomation C# UIAutomation C# UIAutomation C# UIAutomation C# UIAutomation C# UIAutomation C# UIAutomation C# UIAutomation C# UIAutomation C# UIAutomation C# UIAutomation C# UI...
http://download.csdn.net/download/chenxu7601257/5163879 之前忘记把dll文件放上去,发现很多评论说需要DLL,今天整理了下把源代码发给大家...项目在Github上的地址: https://github.com/chenxu7601257/UIAutomation
Python-UIAutomation-for-Windows 是一个强大的Python库,主要用于Windows平台上的UI自动化测试和操作。这个模块基于.NET Framework中的UI Automation技术,允许开发者无须直接交互就能控制和测试图形用户界面(GUI...
在IT行业中,UIAutomation和Spy++是两种强大的工具,用于自动化测试、调试和理解Windows应用程序的用户界面。本文将深入探讨这两个工具以及如何在Win10环境下利用它们获取桌面文件信息和模拟鼠标操作。 首先,UI...
Python QQ群消息自动复制项目利用了`uiautomation`库,这是一个强大的Windows GUI自动化工具,主要用于模拟用户界面操作。在本文中,我们将深入探讨如何使用Python和`uiautomation`库来实现QQ群消息的自动复制功能。...
C#作为.NET框架的主要编程语言,提供了丰富的工具和库来支持自动化测试,其中包括Code UI Automation。本篇将深入探讨如何利用Code UI Automation实现黑盒自动化测试工具,并结合一个名为...
"基于C# UI Automation自动化测试自动化测试示例工程" 是一个使用C#编程语言构建的项目,其核心目标是实现UI(用户界面)自动化测试。UI Automation是.NET Framework提供的一种用于测试Windows应用程序用户界面的...
根据UIAutomation封装了很多自定义方法 现在只需要实例化之后 直接调用方法即可完成。比如单击某个按钮,现在只需要直接调用ClickElement,非常实用。 ClickElement 单击指定的自动化元素 ...
本篇将深入探讨Android的UI自动化测试技术,特别是围绕“uiautomation”这一主题,我们将涵盖以下几个方面: 1. **UIAutomator框架介绍** UIAutomator是Google提供的一个跨应用的UI测试框架,适用于系统级的UI测试...
1. UIAutomationProvider.dll:提供UI自动化服务端功能。 2. UIAutomationTypes.dll:包含UI自动化类型定义。 3. UIAutomationClient.dll:提供UI自动化客户端支持。 4. UIAutomationCore.dll:作为UI自动化的核心,...
本人写的python封装微软UIAutomation API,使编写UI自动化脚本非常容易。支持py2,py3,x86,x64,支持MFC, WindowsForm, WPF, Modern UI(Metro UI), Qt, FireFox等程序的UI自动化。 用法参考:...
在Windows平台上,一个常用的工具是**UISpy**,它对于开发者和测试工程师来说是进行**uiautomation**(UI自动化)不可或缺的辅助工具。 **UISpy**是由Microsoft提供的一款免费的可视化工具,主要用于检查和分析...
资源分类:Python库 所属语言:Python 使用前提:需要解压 资源全名:uiautomation-1.1.8-py2.py3-none-any.whl 资源来源:官方 安装方法:https://lanzao.blog.csdn.net/article/details/101784059
在IT行业中,UIAutomation是一种自动化测试技术,主要用于测试用户界面(UI)的功能和交互性。这一技术被广泛应用在Windows操作系统中,特别是在开发和调试辅助功能(Accessibility)时。本篇文章将详细探讨“UI...
UIAutomation UIElemenet 目前是WinForm+WPF ,后期有Web项目的 ,也会上传 外加一个AccExplorer32.exe Inspect.exe UISpy.exe 总之物超所值,希望能帮到你
uiautomation模块 :China: 不要使用3.7.6和3.8.1,comtypes在这两个版本中不起作用。 安装早期版本或最新版本。 该模块是用于在Windows(视窗XP与SP3中,Windows Vista,Windows 7和视窗8 / 8.1 / 10)。 它支持...
au3_uiautomation UI自动化是AutoIt的一个被忽略的部分。 该项目的目标很简单:以最先进的方式获取UI自动化库以包含在AutoIt核心库中,并且无需了解UIA核心概念就可以更轻松地使用该库。 在开始生产之前,请使用 这...
uiautomation模块 :China: 不要使用3.7.6和3.8.1,comtypes在这两个版本中不起作用。 安装早期版本或最新版本。 该模块是用于在Windows(视窗XP与SP3中,Windows Vista,Windows 7和视窗8 / 8.1 / 10)。 它支持...