Touch interactions

Targeting Elements

Touch interactions may accept a target element to play the interaction on. An element is described with an "Element Selector"; a convenient to way to target a UI element on the device.

An Element Selector describes the element in your application by its attributes and other properties. Below is a list of accepted attributes for each platform.

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

Element Attributes

Attribute
Description

accessibilityIdentifier

accessibilityLabel

The element's accessibilityLabel

accessibilityHint

The element's accessibilityHint

accessibilityValue

The element's accessibilityValue

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: {
    attributes: { 
      text: "OK"
    }
  }  
})

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

// tap on an element by *both* text and accessibilityIdentifier
await session.tap({
  element: {
    attributes: {
      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.

iOS

On iOS, you should be using accessibilityIdentifier.

Android

On Android, you should be using resource-id.

React Native

On React Native, a testID property on your component will map to accessibilityIdentifier on iOS and resource-id on Android.

Sample

If you do not have an accessibilityId to reference it is best to query elements by text or accessibility attributes such as accessibilityLabel (iOS) or content-desc (Android).

Methods

findElement

Returns an element that matches the selector. This is useful for waiting until an element appears.

If multiple elements are found it will return the first element.

findElements

Returns an array of all elements matching that selector.

swipe

Swipes from the screen position or element

By position

By element

Complex Gestures

You can describe a more complex gesture by providing a function to gesture.

tap

Taps on the specified element or coordinates

You can set a duration for a tap to simulate holding it down. For example, if you set it to 2 seconds, the tap will stay pressed for 2 seconds before releasing.

By position or coordinate

By element

Timeouts

Interactions that target an element will wait up to 10 seconds to find the element. You may lower these timeouts by passing a second parameter:

Last updated