Examples
Practical testrelic-appium examples: Android assertions, an iOS XCUITest capability block, step-by-step screenshots, and CI.
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.
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.
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
The on-every-step screenshot policy is meant for deep debugging, capturing a screenshot after every command:
[tool.pytest.ini_options]
testrelic_options = [
"includeScreenshots=true",
"screenshotOnEvery=on-every-step",
]In 0.2.4, per-step capture isn't wired up yet, so on-every-step takes one screenshot at the end of each test (the same as on). Use on-failure (the default) for normal CI runs.
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.
- name: Run Appium tests
env:
TESTRELIC_API_KEY: ${{ secrets.TESTRELIC_API_KEY }}
TESTRELIC_RUN_TYPE: ci
run: |
pip install testrelic-appium
pytestWhen tests are sharded across jobs, merge the per-shard timelines before publishing:
testrelic-appium merge shard-1.json shard-2.json -o merged.json