Touch interactions

Targeting Elements

Touch interactions will usually require a target element. An element can be described using our Element Selector API; a convenient to way to target a UI element on the device.

A selector is comprised of attributes that describe the element in your application. Below is a list of attributes you can describe for each platform.

circle-info

Element selectors work regardless of the device or screen size, meaning you can run the same set of actions on both a phone and tablet

Attribute
Description

accessibilityIdentifier

Value of the element's accessibilityIdentifier

accessibilityLabel

Value of the element's accessibilityLabel

baseClass

Name of the element's base (or inherited) class

ex: UIView

class

Name of the element's class ex: MyCustomUIView

text

Text content of the element and its children (case sensitive)

Any mixture of these attributes can be used to describe your element:

// tap on an element by text
await session.tap({
  element: {
    text: "OK"
  }  
})

// (iOS) tap on an element by accessibilityIdentifier
await session.tap({
  element: {
    accessibilityIdentifier: "dialog-confirm-button"
  }  
})

// tap on an element by *both* text and accessibilityIdentifier
await session.tap({
  element: {
    text: "OK",
    accessibilityIdentifier: "dialog-confirm-button"
  }  
})

Best Practices

When developing your app, we recommend adding accessibility identifiers wherever possible to aid you when automating interactions with Appetize. This will allow for simpler queries and also help your app be more accessible.

On iOS, you should be using accessibilityIdentifier.

On Android, you should be using content-desc or resource-id.

If you are using React Native, a testID prop on your component will map to accessibilityIdentifier on iOS and resource-id on Android.

If you do not have an accessibility id to reference it is best to describe elements by text, adding additional attributes as necessary.

Timeouts

All interactions that target an element will wait up to 30 seconds to find the element. If the element is not found, it will throw an error.

Methods

findElement

Returns an element that matches the selector. This is useful if you need to wait for an element to appear before doing another action.

If multiple elements are found it will throw an error. If you want to get all of them you can use findElements. Otherwise you can provide an index to get the nth element.

findElements

Returns an array of all elements matching that selector. It will error if no elements are found.

swipe()

Plays a swipe gesture at the coordinate or specified element

By coordinates

Coordinates can be specified in either px or % (of screen).

By element

When an element is targeted, % values will correlate to the height/width of the element rather than the screen.

Complex Gestures

If you have a more complex gesture you can build one by providing a function to the gesture argument.

The move function takes x, y arguments and defines the points in the path of your gesture. Each chained move() is relative to the previous point.

tap()

Taps on the specified element or coordinates

type()

Types the given text

Last updated