| description |
|---|
The Session in Appetize makes it easy to manage and interact with device sessions, including simulating user actions, toggling device states, retrieving device information and more. |
Listens for an event of the given name
session.on(event, data => {
console.log(data)
})| Event | Data Type | Description |
|---|---|---|
| RecordedAction | A user action has been recorded. This can be played back later with playAction. |
|
void |
App launch event occurred. | |
|
Audio frames of the current session. |
|
{ message: string } |
An error has occurred on the session | |
void |
First video frame received. | |
{ secondsRemaining: number } |
Session is about to timeout due to inactivity. Any user interaction or a heartbeat will reset the timeout. |
|
| UserInteraction | User has interacted with the device. | |
{ message: string } |
Debug log from the device |
|
| NetworkRequest | NetworkResponse | Intercepted network request or responses. Requires proxy to be set to |
|
'portrait' | 'landscape' |
The device has changed orientation | |
|
Video frames of the current session. |
|
void |
The session has ended |
Ends the session
await session.end()Rotates the device 90 degrees
await session.rotate('right')Parameters
| Name | Type | Description |
|---|---|---|
| direction | "left" | "right" |
The direction to rotate |
Takes a screenshot of the device and returns the data
const { data, mimeType } = await session.screenshot(format)Parameters
| Name | Type | Description |
|---|---|---|
| format? | "buffer" | "base64" |
The format of the screenshot data to return. Defaults to buffer |
Sends a heartbeat to the server, resetting the inactivity timer
await session.heartbeat()Taps on the screen at the given position, coordinate or element
await session.tap({ position: { x: '50%', y: '50%' } })
await session.tap({ coordinates: { x: 100, y: 100 } })
await session.tap({ element: { attributes: { text: 'OK' } } })Parameters
| Name | Type | Description |
|---|---|---|
| target.coordinates? |
|
The coordinates in dip units |
| target.position? |
|
The position on screen in % |
| target.element? | ElementSelector |
An element selector |
| target.duration? | number |
Duration of the tap |
| options.timeout? | number |
If an element is provided, the amount of time to wait for it to appear in ms (defaults 10s) |
| options.matchIndex? | number |
If multiple elements match the element selector, select the nth one |
Swipes on the screen at the given position, coordinate or element
await session.swipe({ position: { x: '50%', y: '50%' }, gesture: 'up' })
await session.swipe({ coordinates: { x: 100, y: 100 }, gesture: 'up' })
await session.swipe({ element: { attributes: { text: 'OK' } }, gesture: 'up' })| target.coordinates? |
|
The coordinates in dip units to start the swipe |
| target.position? |
|
The position on screen in % |
| target.element? | ElementSelector |
An element selector |
| target.duration? | number |
Duration of the swipe |
| target.gesture | string | function |
The gesture of the swipe. See swipe for more details |
| options.timeout? | number |
If an element is provided, the amount of time to wait for it to appear in ms (defaults 10s) |
| options.matchIndex? | number |
If multiple elements match the element selector, select the nth one |
Types the given text on the device
await session.type("hello")Parameters
| Name | Type | Description |
|---|---|---|
| text | string |
Text to type |
{% hint style="warning" %} Typing is limited to 1000 characters at a time to ensure optimal performance and prevent potential disruptions. For larger payloads, you can use multiple 'type' operations. {% endhint %}
Sends a single key press to the device
await session.keypress("a")Parameters
| Name | Type | Description |
|---|---|---|
| key | string |
Key to send to the device ('a', 'b', etc.) |
| options.shift? | boolean |
(iOS 13+ and Android 10+) Sets dark or light mode UI.
await session.setAppearance("dark")Parameters
| Name | Type |
|---|---|
| appearance | "dark" | "light" |
Changes the current language and restarts the app
await session.setLanguage("fr"){% hint style="warning" %}
If your app does not automatically handle language/locale changes, you would need to explicitly call restartApp for this to take effect.
Some apps might also cache data in the previously used language. In these cases use reinstallApp to clear any previous cached data.
{% endhint %}
Parameters
| Name | Type | Description |
|---|---|---|
| language | string |
Language code |
Sets the simulated location of the device.
await setLocation(-33.924434, 18.418391)| Name | Type | Description |
|---|---|---|
| latitude | number |
Decimal number between -90 and 90, representing the degrees of north or south of the Equator. Negative numbers indicate south of the Equator, and positive numbers indicate north of the Equator. |
| longitude | number |
Decimal number between -180 and 180, representing the degrees of east or west of the Prime Meridian. Negative numbers indicate west of the Prime Meridian, and positive numbers indicate east of the Prime Meridian. |
Opens a deep-link or web URL
await session.openUrl("https://appetize.io")Parameters
| Name | Type | Description |
|---|---|---|
url |
string |
The URL |
Shakes device
await session.shake()Toggles the soft keyboard (iOS only)
await session.toggleSoftKeyboard()Sets the biometry enrollment status (iOS Only)
await session.biometryEnrollment(true/false)Simulate a matching fingerprint (Android 8+ only) or Face ID (iOS)
await session.biometry({
match: true/false
})
Enables or disables all interactions on the device. Default is true.
await session.allowInteractions(true/false)Executes an adb shell command on the device (Android only)
await session.adbShellCommand("am start -a android.intent.action.VIEW -d https://appetize.io/")Launches the specified application using the provided appId.
{% hint style="info" %} If the app is already running, it will be brought to the foreground instead of being relaunched. If the app was originally launched with params or a launchUrl, these will also be passed with this method. {% endhint %}
await session.launchApp(appId)Parameters
| Name | Type | Description |
|---|---|---|
appId |
string |
Android: |
Restarts the app
await session.restartApp()Reinstalls the app
await session.reinstallApp()Returns the UI as an XML string
await session.getUI(){% hint style="warning" %}
Experimental
The data structure of the response is subject to change
{% endhint %}
{% tabs %} {% tab title="Old Engine" %} Returns an array of elements, with app and system content separated into two sections.
[
{
"type": "app",
"appId": {running app},
"children": [ ... ] // Your app content
},
{
"type": "app",
"appId": "com.apple.springboard",
"children": [ ... ] // Springboard (system UI) content
}
]{% endtab %}
{% tab title="New Engine" %} A single combined hierarchy is returned, representing what’s actually visible to the user.
[
{
"type": "app",
"appId": {possible appId},
"children": [ ... ] // All visible content on screen (e.g. Springboard/Navigation etc. related content too)
}
]{% endtab %} {% endtabs %}
{% hint style="info" %} The maximum file size for uploading media is 50 MB. {% endhint %}
Upload media to the device.
await session.addMedia(file)Platform specific format support applies. See the Media - Supported File Types documentation for supported file types on Android and iOS.
Returns an element that matches the selector. See Targeting Elements.
This is useful for waiting until an element appears.
const element = await session.findElement({
attributes: {
text: "Home"
}
})If multiple elements are found it will return the first element.
Returns an array of all elements matching that selector. See Targeting Elements.
const elements = await session.findElements({
attributes: {
accessibilityLabel: 'Like post'
}
})Play an automation Action or array of Actions.
await session.playAction(action)Parameters
| Name | Type | Description |
|---|---|---|
| action | Record<string, any> |
Actions emitted from the session.on('action') event |
| options.timeout? | number |
Amount of time in ms to wait for the action to succeed (default 10s) |
Plays an array of actions.
await session.playActions(actions)Parameters
| Name | Type | Description |
|---|---|---|
| actions | Array<Record<string, any>> |
Actions emitted from the session.on('action') event |
| options.timeout? | number |
Amount of time in ms to wait for an action to succeed (default 10s) |
Waits until the there are no ongoing animations on the screen by waiting for the image to stabilize for at least 1 second.
await session.waitForAnimations(options)Parameters
| Name | Type | Description |
|---|---|---|
| options.imageThreshold? | number |
The threshold for the amount of pixels (in %) that can change between frames before the image is considered to be stable. |
| options.timeout? | number |
The maximum amount of time (in ms) to wait for the image to stabilize. |
Waits for an event to occur
const networkEvent = await session.waitForEvent('network')
const requestEvent = await session.waitForEvent('network', event => {
// resolves only when this condition is met
return event.type === 'request'
})Parameters
| Name | Type | Description |
|---|---|---|
| event | string |
One of the session events. |
| options.timeout? | number | null |
The maximum time (in milliseconds) to wait for the event to be emitted. |
| options.predicate? | (data: T) => boolean |
The predicate condition to be satisfied, otherwise the function will continue to wait for the event. |
Waits for the given time to elapse (in ms)
await session.waitForTimeout(5000)Parameters
| Name | Type | Description |
|---|---|---|
| timeout | number |
Timeout in milliseconds. |
Waits until the session is fully initialised and ready for use.
Info for connecting to the Android devices via adb. Requires enableAdb to be true.
See AdbConnectionInfo.
The Appetize app for the session, if applicable.
See AppetizeApp.
The config applied to the current session.
See SessionConfig.
The current device. See DeviceInfo.
The URL to chrome dev tools to inspect network logs. Requires proxy to be set to intercept.
The URL to the Appetizer server.
The token of the Appetize session.