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 qq群消息自动复制,uiautomation
根据UIAutomation封装了很多自定义方法 现在只需要实例化之后 直接调用方法即可完成。比如单击某个按钮,现在只需要直接调用ClickElement,非常实用。 ClickElement 单击指定的自动化元素 ...
资源分类:Python库 所属语言:Python 资源全名:uiautomation-1.0.9.zip 资源来源:官方 安装方法:https://lanzao.blog.csdn.net/article/details/101784059
uiautomation模块源码
1:使用Code UI Automation来录制手工操作UI的动作,让VS根据这些操作自动生成测试代码; 2:新建WINFORM项目(也即黑盒工具),在这个WINFORM项目调用这些自动生成的代码;
资源分类:Python库 所属语言:Python 使用前提:需要解压 资源全名:uiautomation-1.1.8-py2.py3-none-any.whl 资源来源:官方 安装方法:https://lanzao.blog.csdn.net/article/details/101784059
UI Automation是Microsoft .NET 3.0框架下提供的一种用于自动化测试的技术,是在MSAA基础上建立的,MSAA就是Microsoft Active Accessibility。UI Automation在某些方面超过了MSAA,UI自动化提供了Windows Vista中,...
本人写的python封装微软UIAutomation API,使编写UI自动化脚本非常容易。支持py2,py3,x86,x64,支持MFC, WindowsForm, WPF, Modern UI(Metro UI), Qt, FireFox等程序的UI自动化。 用法参考:...
获取win10桌面文件信息及坐标并模拟鼠标双击 所用资源文件 具体代码见帖子 基于4.52包含spy++和UIAutomation引用类库
Test IOS Apps with UI Automation
NULL 博文链接:https://myeyeofjava.iteye.com/blog/1774481
在Mac上搭建Android 自动化测试的测试环境 一、 1. 该环境搭在了本地的一台MacBook上,序列号:C02F302EDC79 2. 使用的自动化测试工具是appium 3. 搭建环境的步骤 1. 在terminal 终端里面运行命令brew install node...
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)。 它支持...
UIAutomation工具UISpy UIAutomation工具UISpy UIAutomation工具UISpy
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核心概念就可以更轻松地使用该库。 在开始生产之前,请使用 这...