Skip to main content
Ask AI

Examples

Copy-paste recipes for common testrelic-appium scenarios.

Android test with named assertions

Use assert_that() to record assertions as discrete, named events on the timeline. Bare assert statements are still captured, but only when they sit outside an assert_that block.

tests/test_login_android.py
import pytest
from appium import webdriver
from appium.options.android import UiAutomator2Options
from testrelic_appium import assert_that

@pytest.fixture
def driver():
options = UiAutomator2Options()
options.platform_name = "Android"
options.device_name = "emulator-5554"
options.app = "/path/to/MyApp.apk"
d = webdriver.Remote("http://127.0.0.1:4723", options=options)
yield d
d.quit()

def test_login_succeeds(driver):
driver.find_element("accessibility id", "username").send_keys("alice")
driver.find_element("accessibility id", "password").send_keys("hunter2")
driver.find_element("accessibility id", "submit").click()

welcome = driver.find_element("accessibility id", "welcome")
with assert_that("toBeDisplayed"):
assert welcome.is_displayed()

with assert_that("toHaveText", expected="Welcome, alice"):
assert welcome.text == "Welcome, alice"

iOS XCUITest capabilities

iOS sessions need macOS with Xcode and the XCUITest driver. The plugin wraps the iOS driver the same way and captures syslog, crashlog, and safariNetwork data.

tests/test_login_ios.py
import pytest
from appium import webdriver
from appium.options.ios import XCUITestOptions

@pytest.fixture
def driver():
options = XCUITestOptions()
options.platform_name = "iOS"
options.platform_version = "17.4"
options.device_name = "iPhone 15"
options.app = "/path/to/MyApp.app"
d = webdriver.Remote("http://127.0.0.1:4723", options=options)
yield d
d.quit()

def test_app_launches(driver):
assert driver.find_element("accessibility id", "home").is_displayed()

Screenshot on every step

For deep debugging, capture a screenshot after every command by setting the screenshot policy to on-every-step:

pyproject.toml
[tool.pytest.ini_options]
testrelic_options = [
"includeScreenshots=true",
"screenshotOnEvery=on-every-step",
]
warning

on-every-step is verbose and slows runs noticeably. Prefer on-failure (the default) for normal CI runs and reserve on-every-step for reproducing a specific flake.

GitHub Actions step

Set the API key as a repository secret and run pytest as usual — uploads happen automatically. See the GitHub Actions integration for the full picture.

.github/workflows/mobile-tests.yml
- name: Run Appium tests
env:
TESTRELIC_API_KEY: ${{ secrets.TESTRELIC_API_KEY }}
TESTRELIC_RUN_TYPE: ci
run: |
pip install testrelic-appium
pytest

When tests are sharded across jobs, merge the per-shard timelines before publishing:

testrelic-appium merge shard-1.json shard-2.json -o merged.json

Next steps