UI Automation JavaScript Reference For iOS

Classes  

NOTE

This document was previously titled UI Automation Reference Collection.

Use the UI Automation JavaScript library to write test scripts that exercise your iOS 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 UIAElement 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;
  • }

Classes

 

UIAActionSheet

Describes the API for automating tests of action sheets.

 

UIAActivityIndicator

Describes the API for automating tests of activity indicator elements in iPhone applications.

 

UIAActivityView

Describes a view for presenting an activity view.

 

UIAAlert

Describes the API for handling alerts in automated UI tests.

 

UIAApplication

New document that describes the API for automating UI tests of iOS applications.

 

UIAButton

Describes the API for automating tests of button elements in iPhone applications.

 

UIACollectionView

Describes a collection view.

 

UIAEditingMenu

Describes the API for automating tests of edit menu elements in iPhone applications.

 

UIAElement

Describes the API for automating tests of user interface elements in iPhone applications.

 

UIAElementArray

Describes the API for using arrays of user interface elements in automated tests of iPhone applications.

 

UIAHost

Describes the API for communicating with a host computer during automated iOS application testing.

 

UIAKey

Describes the API for automating keyboard UI elements.

 

UIAKeyboard

Describes the API for automating tests of keyboard elements in iPhone applications.

 

UIALink

Describes the API for automating tests of URL elements in iPhone applications.

 

UIALogger

Describes the API for logging data from automated tests of UI elements in iPhone applications.

 

UIANavigationBar

Describes the API for automating tests of navigation bar elements in iPhone applications.

 

UIAPageIndicator

Describes the API for automating tests of page indicator elements in iPhone applications.

 

UIAPicker

Describes the API for automating tests of picker elements in iPhone applications.

 

UIAPickerWheel

Describes the API for automating tests of picker wheels.

 

UIAPopover

Describes the API for automating tests of progress indicator elements in iPhone applications.

 

UIAProgressIndicator

Describes the API for automating tests of progress indicator elements in iPhone applications.

 

UIAScrollView

Describes the API for automating tests of scroll view elements in iPhone applications.

 

UIASearchBar

Describes the API for automating tests of search bar elements in iPhone applications.

 

UIASecureTextField

Describes the API for automating tests of secure text field elements in iPhone applications.

 

UIASegmentedControl

Describes the API for automating tests of segmented control elements in iPhone applications.

 

UIASlider

Dscribes the API for automating tests of slider UI elements in iPhone applications.

 

UIAStaticText

Describes the API for automating tests of static text elements in iPhone applications.

 

UIAStatusBar

Describes the API for automating tests of status bar elements in iPhone applications.

 

UIASwitch

Describes the API for automating tests of switch UI elements in iPhone applications.

 

UIATabBar

Describes the API for automating tests of tab bar elements in iPhone applications.

 

UIATableCell

Describes the API for automating tests of table cell elements in iPhone applications.

 

UIATableGroup

Describes the API for automating tests of table group elements in iPhone applications.

 

UIATableView

Describes the API for automating tests of table view elements in iOS apps.

 

UIATarget

Describes the API for automating tests of UI elements in iPhone applications.

 

UIATextField

Describes the API for automating tests of text field elements in iPhone applications.

 

UIATextView

Describes the API for automating tests of text view elements in iPhone applications.

 

UIAToolbar

Describes the API for automating tests of toolbar elements in iPhone applications.

 

UIAWebView

Describes the API for automating tests of web view elements in iPhone applications.

 

UIAWindow

Describes the API for automating tests of window elements in iPhone applications.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
根据UIAutomation封装了很多自定义方法 现在只需要实例化之后 直接调用方法即可完成。比如单击某个按钮,现在只需要直接调用ClickElement,非常实用。 ClickElement 单击指定的自动化元素 DisselectAllDataGridRow 不选中所有行 DisselectDataGridRow 不选中特定的某一行 FocusWindow 获取窗口焦点 GetAllElement 获取指定父自动化元素下的所有激活的控件 GetAllElementDetails 获取指定自动化元素下的详细信息包括AutomationID,ControlType以及Name GetAllMenus 获取所有菜单项 GetAllSubMenus 获取某个菜单下的所有子菜单项 GetColumnsFromGridLine 获取指定行的所有列 GetColumnValuesFromGridLine 获取行的每一列数据 GetControlType(AutomationElement) 获取制动自动化元素的控件类型 GetControlType(TypeOfControl) 获取UIAutomation的控件类型 GetDocumentText 获取document控件的值 GetElementByID 获取父自动化元素下指定元素控件ID的引用 GetElementByName 获取父自动化元素下的指定子元素的引用 GetElementsByControlType 获取父自动化元素下的特定类型的所有自动化元素 GetGridLinesFromDataGrid 获取网格控件的全部行元素的引用 GetHeaderFromDataGrid 获取指定网格控件的标题栏引用 GetMenuBar 获取菜单栏控件 GetMenuByName 通过特定的名称去获取菜单UI自动化元素 GetName 获取指定自动化元素的名称 GetSubMenuByName 获取主菜单下的指定子菜单项的引用 GetValue 获取指定自动化元素的值 GetWindowByName(String) 获取desktop下的指定窗口名称的子UI自动化元素 GetWindowByName(String, AutomationElement) 获取特定父UI自动化元素下的制定窗口名称的子UI自动化元素 GetWindowList() 获取当前桌面根下所有的UI自动化元素下 GetWindowList(AutomationElement) 获取特定父UI自动化元素下的所有窗口的名称 RefindMainApplication 重新获取desktop下的指定窗口的自动化元素引用 SelectAllDataGridRow 选中所有行 SelectDataGridRow(AutomationElement) 选中特定的某一行 SelectDataGridRow(AutomationElement, Boolean) 将特定的DateGridRow加入选中项中 SelectValueInComboBox 从下拉框中选中指定值的项 SelectValueInListBox 从列表中选中指定值的项 SetValue 给予指定自动化元素赋值 以上的方法还不是很完善 正在完善中。如果有什么意见和建议,请发送邮件获取 chenxu7601257@qq.com 如果你看了这个帮助文件之后觉得有用的,请发邮件获取,我将把dll文件给你。谢谢。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值