iOS Reference Library Apple Developer
Search

UIATarget Class Reference

Availability
Available in iOS 4.0 and later.

Overview

The UIATarget class represents high-level user interface elements of the system under test (SUT)—that is, your application, the iOS, and the connected device on which they’re running. Your test scripts, written in JavaScript and running in conjunction with the UI Automation instrument, use this class and related UIA classes to exercise the SUT and log results.

For the sake of simplicity and consistency with other Apple documentation, this document describes device operations and user interface actions as though they were performed by a user. In practice, the Automation instrument simulates these operations and actions.

Tasks

Getting the Base Target Object

Managing Your Application

Obtaining Device Property Information

Use these methods to obtain information specific to the device such as assigned name, device model, and operating-system name and version.

Determining and Changing Device Orientation

Device Controls and Actions

Screen Interaction

The rect and point objects used with these screen interaction methods have properties for origin, size, x, y, height, and width corresponding to the analogous CGRect, CGPoint, and CGSize Cocoa structures. Your script should treat methods with rect, point, or size arguments or return types as JavaScript objects with those properties defined. The relevant coordinates are screen-relative and are adjusted to account for device orientation.

Capturing Screen Images

These methods allow you to record the appearance of the screen (or some portion of it). Such images can be helpful in tracking progress in a test and in diagnosing problems.

Timeouts

Miscellaneous

Methods

captureRectWithName

Takes a screen shot of the specified rectangular portion of the device screen.

(undefined) captureRectWithName(Rect rect, String imageName)

Parameters
rect

The rect that defines the area of the screen to capture.

imageName

A string to use as the name for the resultant image file.

Discussion

The image is saved as a file in .PNG graphic format, with the specified name, in the log.

captureScreenWithName

Takes a screen shot of the entire device screen.

(undefined) captureScreenWithName(String imageName)

Parameters
imageName

A string to use as the name for the resultant image file.

Discussion

The image is saved as a file in .PNG graphic format, with the specified name, in the log.

clickVolumeDown

Presses the Volume down hardware button.

(undefined) clickVolumeDown()

clickVolumeUp

Presses the Volume up hardware button.

(undefined) clickVolumeUp()

deactivateAppForDuration

Renders your application inactive for the specified duration.

(Boolean) deactivateApp(Number duration)

Parameters
duration

The time, in seconds, for the application to remain inactive.

Discussion

Use this method to test shifting your application to and from the background execution context. Note that applications built using iPhone SDK 4.0 or later and running in iOS 4.0 and later aren’t necessarily terminated when the user presses the Home button. See iOS Application Programming Guide for details of multitasking and background execution context.

delay

Delays script execution for the specified time.

(Boolean) delay(Number timeInterval)

Parameters
timeInterval

The time to delay, in seconds.

Discussion

You can use this method to provide enough time for lengthy operations to complete.

deviceOrientation

Returns the current orientation of the device.

(Number deviceOrientation) deviceOrientation()

Discussion

The returned value is a constant that represents the physical orientation of the device and may be different from the current orientation of your application’s user interface. The possible values are as follows:

  • UIA_DEVICE_ORIENTATION_UNKNOWN

  • UIA_DEVICE_ORIENTATION_PORTRAIT

  • UIA_DEVICE_ORIENTATION_PORTRAIT_UPSIDEDOWN

  • UIA_DEVICE_ORIENTATION_LANDSCAPELEFT

  • UIA_DEVICE_ORIENTATION_LANDSCAPERIGHT

  • UIA_DEVICE_ORIENTATION_FACEUP

  • UIA_DEVICE_ORIENTATION_FACEDOWN

See the Constants section for descriptions of these values.

doubleTap

Double-taps the specified element or at the specified screen location.

(undefined) doubleTap(Object tapPointObject)

Parameters
tapPointObject

A rect, point, or UIAElement.

dragFromToForDuration

Drags from a specified starting screen location to a specified ending screen location, for a specified length of time.

(undefined) dragFromToForDuration(fromPointObject, toPointObject, Number duration)

Parameters
fromPointObject

The rect or point from which the drag action is to begin.

toPointObject

The rect or point at which the drag action is to end.

duration

The length of time, in seconds, between starting and stopping the gesture.

flickFromTo

Flicks from the specified starting screen location to the specified ending screen location.

(undefined) flickFromTo(fromPointObject, toPointObject)

Parameters
fromPointObject

The rect or point from which the flick action is to begin.

toPointObject

The rect or point at which the flick action is to end.

frontMostApp

Returns an object representing your application.

(UIAApplication) frontMostApp()

Discussion

This UIAApplication object is the centralized point of control and coordination for your application.

holdVolumeDown

Holds down the Volume down hardware button for the specified duration.

(undefined) holdVolumeDown(Number duration)

holdVolumeUp

Presses and holds the Volume up hardware button for the specified duration.

(undefined) holdVolumeUp(Number duration)

localTarget

This class method returns a UIATarget object representing the system under test (SUT).

(UIATarget) localTarget()

lock

Locks the device, using a lock event.

(undefined) lock()

model

Returns the device model.

(String) model()

Discussion

Examples of model strings are iPhone and iPod touch.

name

Returns the device name.

(String) name()

Discussion

The device name is an arbitrary string specified for the device by the user. On an iPhone, for example, you can see the name on the device in the General > About settings or in iTunes on the Summary > iPhone tab.

pinchCloseFromToForDuration

Pinches (performs a pinch-close gesture) from a specified starting screen location to a specified ending screen location, for a specified length of time.

(undefined) pinchCloseFromToForDuration(fromPointObject, toPointObject, Number duration)

Parameters
fromPointObject

The rect or point from which the pinch-close action is to begin.

toPointObject

The rect or point at which the stretch pinch-close action is to end.

duration

The length of time, in seconds, between starting and stopping the gesture.

pinchOpenFromToForDuration

Stretches (performs a pinch-open gesture) from a specified starting screen location to a specified ending screen location, for a specified length of time.

(undefined) pinchOpenFromToForDuration(fromPointObject, toPointObject, Number duration)

Parameters
fromPointObject

The rect or point from which the pinch-open action is to begin.

toPointObject

The rect or point at which the pinch-open action is to end.

duration

The length of time, in seconds, between starting and stopping the gesture.

popTimeout

Retrieves the previous timeout value from a stack, restores it as the current timeout value, and returns it.

(Number) popTimeout()

Return Value

The timeout value last stored on the stack with pushTimeout.

Discussion

Use this method to revert to the previous grace period duration.

If an object representing a UI element becomes available within the grace period, an attempt is made to instantiate that object from information retained by the instrument.

pushTimeout

Stores the current timeout value on a stack and sets a new timeout value.

(undefined) pushTimeout(timeoutValue)

Parameters
timeout

The length of the grace period, in seconds.

Discussion

This method, in conjunction with popTimeout, allows you to temporarily change the duration of the grace period for object resolution.

If an object representing a UI element becomes available within the grace period, an attempt is made to instantiate that object from information retained by the instrument.

setDeviceOrientation

Changes the device orientation to the specified new deviceOrientation value.

(undefined) setDeviceOrientation(Number deviceOrientation)

Discussion

The specified deviceOrientation value must be one of the following constants:

  • UIA_DEVICE_ORIENTATION_UNKNOWN

  • UIA_DEVICE_ORIENTATION_PORTRAIT

  • UIA_DEVICE_ORIENTATION_PORTRAIT_UPSIDEDOWN

  • UIA_DEVICE_ORIENTATION_LANDSCAPELEFT

  • UIA_DEVICE_ORIENTATION_LANDSCAPERIGHT

  • UIA_DEVICE_ORIENTATION_FACEUP

  • UIA_DEVICE_ORIENTATION_FACEDOWN

See the Constants section for descriptions of these values.

setTimeout

Sets a new timeout value.

(undefined) setTimeout(Number timeout)

Parameters
timeout

A number representing the length of the grace period, in seconds.

Discussion

The timeout value establishes a grace period for object resolution. If an object representing a UI element becomes available within the grace period, an attempt is made to instantiate that object from information retained by the instrument.

shake

Shakes the device.

(undefined) shake()

systemName

Returns the name of the operating system running on the device

(String) systemName()

systemVersion

Returns the current version of the operating system running on the device.

(String) systemVersion()

Discussion

An example of a system version string is 1.2.

tap

Taps the specified element or the specified screen location.

(undefined) tap(Object tapPointObject)

Parameters
tapPointObject

A rect, point, or UIAElement.

tapWithOptions

Taps the specified element or at the specified screen location with the specified options.

(undefined) tapWithOptions(Object tapPointObject, Object options)

Parameters
tapPointObject

A rect, point, or UIAElement.

options

Characteristics that you provide to specify the type of tap gesture to perform.

timeout

Returns the current timeout value.

(Number) timeout()

Discussion

The timeout value establishes a grace period for object resolution. If an object representing a UI element becomes available within the grace period, an attempt is made to instantiate that object from information retained by the instrument.

touchAndHold

Touches the specified element or at the specified screen location and holds for the specified duration.

(undefined) touchAndHold(Object tapPointObject, Number duration)

Parameters
tapPointObject

A rect, point, or UIAElement.

duration

The length of time, in seconds, to hold the touch.

unlock

Unlocks the device using an unlock event followed by a drag of the slider.

(undefined) unlock()

Discussion

Simulating passcode entry is currently unsupported. Set the Settings > General > Passcode Lock feature to Off prior to running your tests.

Event Handlers by Task

Handling Alerts



Event Handlers

onAlert

Called by UI Automation to allow your script to respond to alerts.

(Boolean) onAlert(UIAAlert alert)
Parameters
alert

An object representing the alert encountered.

Return Value

Return true if successful. Return false to cause the default alert handler to run.

Discussion

Your onAlert handler is called if an alert is encountered at any time during the execution of the script. If you do not have a declared onAlert handler, the UI Automation default alert handler runs instead.

This default handler simply attempts to dismiss the alert by first tapping the cancel button, if it exists, then tapping the default button, if one is identifiable. If the alert is still not dismissed, an exception is thrown.

Returning false from your own handler also causes the default handler to run. For cursory tests, the script handler might just log an alert message and return false to let the default handler dismiss the alert.

Constants

Constant

Description

UIA_DEVICE_ORIENTATION_UNKNOWN

The orientation of the device cannot be determined.

UIA_DEVICE_ORIENTATION_PORTRAIT

The device is in portrait mode, with the device upright and the home button at the bottom.

UIA_DEVICE_ORIENTATION_PORTRAIT_UPSIDEDOWN

The device is in portrait mode but upside down, with the device upright and the home button at the top.

UIA_DEVICE_ORIENTATION_LANDSCAPELEFT

The device is in landscape mode, with the device upright and the home button on the right side.

UIA_DEVICE_ORIENTATION_LANDSCAPERIGHT

The device is in landscape mode, with the device upright and the home button on the left side.

UIA_DEVICE_ORIENTATION_FACEUP

The device is parallel to the ground with the screen facing upward.

UIA_DEVICE_ORIENTATION_FACEDOWN

The device is parallel to the ground with the screen facing downward.




Last updated: 2010-05-27

Did this document help you? Yes It's good, but... Not helpful...