Mobile Testing Examples
- For AI agents
- For Human
Write Appium tests with an AI assistant
Copy any prompt below and paste it into your AI coding assistant to generate ready-to-run tests.
Android native app test
Write a WebdriverIO/Appium test file for Android using @wdio/globals.
The test should:
1. Verify the home screen loads and a title element (~AppTitle) is visible
2. Add a new task by clicking ~AddTaskButton, filling an input, saving, and verifying it appears in the list
3. Mark a task as complete by clicking its checkbox
Use describe/it blocks with mocha syntax.
Use async/await throughout.
iOS native app test
Write a WebdriverIO/Appium test file for iOS using @wdio/globals.
The test should:
1. Verify a Calculator app display (~Display) is visible on launch
2. Perform a basic addition: 2 + 3 = 5, verify the display shows '5'
3. Clear the display with the ~AC button and verify it shows '0'
Use describe/it blocks with mocha syntax.
Use async/await throughout.
Mobile web test
Write a WebdriverIO test file for testing a mobile web app at https://example-shop.com/products.
The test should:
1. Verify the product grid ([data-testid="product-grid"]) is displayed
2. Click the first product card and verify the product title and add-to-cart button are visible
3. Verify the mobile hamburger menu button is visible and opens the nav when clicked
Use describe/it blocks. Use async/await throughout.
Cross-platform WDIO config
Create a wdio.conf.ts that runs tests on both Android and iOS simultaneously using maxInstances: 2.
Include:
- Android capability: UiAutomator2, emulator-5554, an APK at apps/MyApp.apk
- iOS capability: XCUITest, iPhone 15, platformVersion 17.0, a .app at apps/MyApp.app
- TestRelicService with screenshotOnEvery: 'failure'
- TestRelicReporter writing to ./test-results/cross-platform-timeline.json
- onComplete hook calling TestRelicReporter.finalize()
Show me the complete config.
These examples show how to write Appium/WDIO tests that work with @testrelic/appium-analytics. The TestRelic service and reporter work in the background — your test code uses standard WDIO/Appium APIs.
These examples show how to write Appium/WDIO tests that work with @testrelic/appium-analytics. The TestRelic service and reporter work in the background — your test code uses standard WDIO/Appium APIs.
Android native app test
Test a native Android app using the UiAutomator2 driver. This example launches a demo app and verifies that a list of items loads correctly.
import { browser, $, $$ } from '@wdio/globals';
describe('Android Native — Todo App', () => {
it('should display the home screen on launch', async () => {
const title = await $('~AppTitle');
await expect(title).toBeDisplayed();
});
it('should add a new task', async () => {
const addButton = await $('~AddTaskButton');
await addButton.click();
const input = await $('android=new UiSelector().className("android.widget.EditText")');
await input.setValue('Buy groceries');
const saveButton = await $('~SaveButton');
await saveButton.click();
const taskList = await $$('~TaskItem');
expect(taskList.length).toBeGreaterThanOrEqual(1);
const lastTask = taskList[taskList.length - 1];
await expect(lastTask).toHaveText('Buy groceries');
});
it('should mark a task as complete', async () => {
const firstTask = await $('~TaskItem:first-child');
await firstTask.click();
const checkbox = await $('~TaskCheckbox');
await checkbox.click();
await expect(checkbox).toHaveAttribute('checked', 'true');
});
});
WDIO config for this example:
import { join } from 'node:path';
import { TestRelicService } from '@testrelic/appium-analytics/service';
import { TestRelicReporter } from '@testrelic/appium-analytics';
export const config = {
runner: 'local',
port: 4723,
path: '/',
specs: ['./tests/android-*.test.ts'],
maxInstances: 1,
capabilities: [{
platformName: 'Android',
'appium:automationName': 'UiAutomator2',
'appium:deviceName': 'emulator-5554',
'appium:platformVersion': '14.0',
'appium:app': join(process.cwd(), 'apps', 'TodoApp.apk'),
'appium:noReset': false,
}],
framework: 'mocha',
mochaOpts: { ui: 'bdd', timeout: 60000 },
services: [
[TestRelicService, {
includeDeviceLogs: true,
includeNetworkLogs: true,
screenshotOnEvery: 'failure',
includeCommands: true,
}],
],
reporters: [
'spec',
[TestRelicReporter, {
outputPath: './test-results/android-timeline.json',
openReport: true,
}],
],
async onComplete() {
await TestRelicReporter.finalize(process.cwd());
},
};
iOS native app test
Test a native iOS app using the XCUITest driver. Requires macOS 13+ with Xcode 15+ and the iOS Simulator.
import { browser, $, $$ } from '@wdio/globals';
describe('iOS Native — Calculator App', () => {
it('should display the calculator on launch', async () => {
const display = await $('~Display');
await expect(display).toBeDisplayed();
});
it('should perform a basic addition', async () => {
await $('~2').click();
await $('~+').click();
await $('~3').click();
await $('~=').click();
const display = await $('~Display');
await expect(display).toHaveText('5');
});
it('should clear the display', async () => {
await $('~AC').click();
const display = await $('~Display');
await expect(display).toHaveText('0');
});
});
WDIO config for this example:
import { join } from 'node:path';
import { TestRelicService } from '@testrelic/appium-analytics/service';
import { TestRelicReporter } from '@testrelic/appium-analytics';
export const config = {
runner: 'local',
port: 4723,
path: '/',
specs: ['./tests/ios-*.test.ts'],
maxInstances: 1,
capabilities: [{
platformName: 'iOS',
'appium:automationName': 'XCUITest',
'appium:deviceName': 'iPhone 15',
'appium:platformVersion': '17.0',
'appium:app': join(process.cwd(), 'apps', 'Calculator.app'),
'appium:noReset': false,
}],
framework: 'mocha',
mochaOpts: { ui: 'bdd', timeout: 60000 },
services: [
[TestRelicService, {
includeDeviceLogs: true,
screenshotOnEvery: 'failure',
preferBiDi: true,
}],
],
reporters: [
'spec',
[TestRelicReporter, {
outputPath: './test-results/ios-timeline.json',
openReport: true,
}],
],
async onComplete() {
await TestRelicReporter.finalize(process.cwd());
},
};
Mobile web test
Test a web application in a mobile browser (Chrome on Android or Safari on iOS). This is useful for verifying responsive layouts and touch interactions.
- Android (Chrome)
- iOS (Safari)
import { browser, $, $$ } from '@wdio/globals';
describe('Mobile Web — Product Listing', () => {
beforeEach(async () => {
await browser.url('https://example-shop.com/products');
});
it('should display the product grid on mobile', async () => {
const grid = await $('[data-testid="product-grid"]');
await expect(grid).toBeDisplayed();
const products = await $$('[data-testid="product-card"]');
expect(products.length).toBeGreaterThan(0);
});
it('should open a product detail page', async () => {
const firstProduct = await $('[data-testid="product-card"]');
await firstProduct.click();
const title = await $('[data-testid="product-title"]');
await expect(title).toBeDisplayed();
const addToCart = await $('[data-testid="add-to-cart"]');
await expect(addToCart).toBeEnabled();
});
it('should show the mobile hamburger menu', async () => {
const hamburger = await $('[data-testid="mobile-menu-button"]');
await expect(hamburger).toBeDisplayed();
await hamburger.click();
const nav = await $('[data-testid="mobile-nav"]');
await expect(nav).toBeDisplayed();
});
});
WDIO config — Chrome on Android:
import { TestRelicService } from '@testrelic/appium-analytics/service';
import { TestRelicReporter } from '@testrelic/appium-analytics';
export const config = {
runner: 'local',
port: 4723,
path: '/',
specs: ['./tests/mobile-web.test.ts'],
maxInstances: 1,
capabilities: [{
platformName: 'Android',
'appium:automationName': 'UiAutomator2',
'appium:deviceName': 'emulator-5554',
browserName: 'Chrome',
}],
framework: 'mocha',
mochaOpts: { ui: 'bdd', timeout: 30000 },
services: [
[TestRelicService, {
includeNetworkLogs: true,
includeConsoleLogs: true,
screenshotOnEvery: 'failure',
}],
],
reporters: [
'spec',
[TestRelicReporter, {
outputPath: './test-results/mobile-web-timeline.json',
openReport: true,
}],
],
async onComplete() {
await TestRelicReporter.finalize(process.cwd());
},
};
import { TestRelicService } from '@testrelic/appium-analytics/service';
import { TestRelicReporter } from '@testrelic/appium-analytics';
export const config = {
runner: 'local',
port: 4723,
path: '/',
specs: ['./tests/mobile-web.test.ts'],
maxInstances: 1,
capabilities: [{
platformName: 'iOS',
'appium:automationName': 'XCUITest',
'appium:deviceName': 'iPhone 15',
'appium:platformVersion': '17.0',
browserName: 'Safari',
}],
framework: 'mocha',
mochaOpts: { ui: 'bdd', timeout: 30000 },
services: [
[TestRelicService, {
includeNetworkLogs: true,
includeConsoleLogs: true,
screenshotOnEvery: 'failure',
preferBiDi: true,
}],
],
reporters: [
'spec',
[TestRelicReporter, {
outputPath: './test-results/ios-web-timeline.json',
openReport: true,
}],
],
async onComplete() {
await TestRelicReporter.finalize(process.cwd());
},
};
Cross-platform test suite
Run the same tests against both Android and iOS by defining multiple capabilities and using maxInstances: 2:
import { join } from 'node:path';
import { TestRelicService } from '@testrelic/appium-analytics/service';
import { TestRelicReporter } from '@testrelic/appium-analytics';
export const config = {
runner: 'local',
port: 4723,
path: '/',
specs: ['./tests/cross-platform.test.ts'],
maxInstances: 2,
capabilities: [
{
platformName: 'Android',
'appium:automationName': 'UiAutomator2',
'appium:deviceName': 'emulator-5554',
'appium:app': join(process.cwd(), 'apps', 'MyApp.apk'),
},
{
platformName: 'iOS',
'appium:automationName': 'XCUITest',
'appium:deviceName': 'iPhone 15',
'appium:platformVersion': '17.0',
'appium:app': join(process.cwd(), 'apps', 'MyApp.app'),
},
],
framework: 'mocha',
mochaOpts: { ui: 'bdd', timeout: 60000 },
services: [
[TestRelicService, {
includeDeviceLogs: true,
screenshotOnEvery: 'failure',
}],
],
reporters: [
'spec',
[TestRelicReporter, {
outputPath: './test-results/cross-platform-timeline.json',
openReport: false,
}],
],
async onComplete() {
await TestRelicReporter.finalize(process.cwd());
},
};
Next steps
- Full configuration reference — all available options
- Cloud quickstart — upload results to TestRelic platform
- @testrelic/appium-analytics package reference — complete API docs and platform setup guides