Skip to content

Write mobile tests ​

A mobile test is a *.test.yaml file like a web test, with two additions at the top: platform, and an app block that names the app under test. Steps use the same intent: and action: form, and STEP, IF, WHILE, parameters, beforeEach, afterEach, teardown, and templates work as they do on the web. See YAML Test Format for the shared structure.

An Android test ​

yaml
goal: Type into a text field and read it back
platform: android
app:
  path: ./build/ApiDemos-debug.apk
  identifier: io.appium.android.apis
statements:
  - intent: Open the Views category
    action: click
    locator: { kind: accessibility_id, value: Views }
  - intent: Scroll to the Controls demo
    action: scroll_to_element
    locator: { kind: accessibility_id, value: Controls }
  - intent: Open the Controls demo
    action: click
    locator: { kind: accessibility_id, value: Controls }
  - intent: Open the light theme controls
    action: click
    locator: { kind: accessibility_id, value: 1. Light Theme }
  - intent: Type into the text field
    action: input_text
    locator: { kind: id, value: io.appium.android.apis:id/edit }
    text: Hello from Shiplight
  - intent: Hide the keyboard
    action: hide_keyboard
  - intent: Check the text field holds the typed text
    action: assert_text
    locator: { kind: id, value: io.appium.android.apis:id/edit }
    equals: Hello from Shiplight

This test uses the open-source ApiDemos app. Every step is explicit, so it runs without AI calls.

An iOS test ​

yaml
goal: Sign in, then replace and clear the username
platform: ios
app:
  path: ./build/MyApp.app
  identifier: com.example.myapp
statements:
  - intent: Open the login screen
    action: click
    locator: { kind: accessibility_id, value: nav.login }
  - intent: Type the username
    action: input_text
    locator: { kind: accessibility_id, value: login.username }
    text: ada
  - intent: Type the password into the secure field
    action: input_text
    locator: { kind: accessibility_id, value: login.password }
    text: "{{PASSWORD}}"
  - intent: Hide the keyboard
    action: hide_keyboard
  - intent: Sign in
    action: click
    locator: { kind: accessibility_id, value: login.submit }
  - intent: Check the greeting
    action: assert_text
    locator: { kind: accessibility_id, value: login.message }
    equals: Welcome, ada
  - intent: Clear the username
    action: clear_input
    locator: { kind: accessibility_id, value: login.username }

On iOS, path is the .app folder that Xcode builds for the simulator, for example with xcodebuild -sdk iphonesimulator. Variables such as {{PASSWORD}} work as in web tests; see Variables.

The app block ​

FieldPlatformsDescription
identifierBothRequired. The Android package name, or the iOS bundle identifier
pathBothThe app to install, relative to the YAML file: an .apk on Android, a simulator .app folder on iOS. Use with a local profile
appIdBothAn app already uploaded to a remote device service. Use with a remote profile instead of path
deviceBothThe device profile to use. Default: defaultDevice, or the only profile
resetPolicyBothfresh (default), reinstall, or none. See below
activityAndroidThe activity to launch. Default: the package's launcher activity
grantPermissionsAndroidGrant the app's runtime permissions on install. Default: true

Set exactly one of path and appId.

Reset policy ​

resetPolicy sets what the app keeps from earlier runs when a test opens it:

PolicyAndroidiOS
fresh (default)Installs your build over the app, then clears its dataRemoves the app and installs your build
reinstallUninstalls the app and installs your buildRemoves the app and installs your build
noneInstalls your build over the app and keeps its dataInstalls your build over the app and keeps its data

Every policy runs the build you name, so a test never runs a stale copy left on the device. With none, if the installed copy can't be updated in place (for example, it was signed with another key), the test stops with a message rather than delete the data. Uninstall the app, or use fresh.

Use none when a test depends on state an earlier test left, and run those files in order with workers: 1.

Locators ​

Native steps locate their element with locator: { kind, value }. Each platform has its own kinds:

KindPlatformMatchesExample
accessibility_idBothThe content description (Android) or accessibility identifier (iOS){ kind: accessibility_id, value: login.submit }
idAndroidThe resource ID{ kind: id, value: com.example.shop:id/email }
uiautomatorAndroidA UiAutomator selector{ kind: uiautomator, value: 'new UiSelector().text("WebView")' }
predicateiOSAn NSPredicate string{ kind: predicate, value: "type == 'XCUIElementTypeButton' AND name == 'add'" }
class_chainiOSAn XCUITest class chain{ kind: class_chain, value: "**/XCUIElementTypeStaticText[`name == 'row.1'`]" }
xpathBothAn XPath over the native element tree{ kind: xpath, value: //android.webkit.WebView }

Prefer accessibility_id, then id on Android. They survive layout changes better than xpath. Inside a WebView, locators are css and xpath over the page's DOM; see Hybrid apps.

Actions ​

Explicit steps take an action: and its parameters. Steps that act on an element also take a locator:.

GroupActions
Touchclick, double_click, long_press, swipe, drag_drop, scroll, scroll_to_element
Textinput_text (clears the field first), clear_input, hide_keyboard
Keys and navigationhome, open_deep_link; on Android also back and press
App lifecyclelaunch_app, terminate_app, reset_app
Deviceset_orientation (portrait or landscape)
System alertsaccept_alert, dismiss_alert, each with an optional exact button name
Assertionsassert_visible, assert_absent, assert_text (with equals or contains)
Screen coordinatescoordinate_tap, coordinate_double_tap, coordinate_long_press, coordinate_drag
Contextsswitch_context (see Hybrid apps)
Otherwait, save_variable, generate_2fa_code

launch_app and terminate_app act on the test app unless you pass another identifier. reset_app clears the test app's data on Android, or reinstalls it on iOS, and relaunches it. A URL: step opens a deep link, so it needs a full URL such as myapp://cart; mobile tests have no base_url.

For every action's parameters, print the reference for a platform:

bash
bun run shiplight spec actions --platform android
bun run shiplight spec actions --platform ios

Some examples:

yaml
  - intent: Press Backspace to delete the last letter
    action: press
    keys: Backspace
  - intent: Open the app through its deep link
    action: open_deep_link
    url: myapp://hello
  - intent: Allow notifications in the system alert
    action: accept_alert
    button: Allow
  - intent: Rotate to landscape
    action: set_orientation
    orientation: landscape
  - intent: Go to the device home screen
    action: home
  - intent: Bring the app back
    action: launch_app

AI steps ​

The AI statements from web tests work on mobile too. Shiplight's hosted service reads the screen and decides each one, so these steps need a Shiplight API token:

yaml
statements:
  - intent: Open the settings
  - VERIFY: The settings screen is shown
  - WAIT_UNTIL: The list has loaded
    timeout_seconds: 20
  - intent: Read the order number
    action: ai_extract
    element_description: the order number
    variable_name: order
  - IF: A dialog is open
    THEN:
      - intent: Close it
        action: back
    ELSE:
      - intent: Go home
        action: home

An intent: with no action: is planned on every run. With a token, an explicit step whose locator no longer matches is healed: Shiplight finds the element again from the step's intent. Assertions are not healed. Without a token, a step whose locator doesn't match fails.

Released under the MIT License.