Test Example in JavaScript
Be sure to checkout the full Appium setup guide with axe DevTools Mobile if you're just getting started, or more examples of axe DevTools Mobile for Appium in other languages.
executeScript in JavaScript
Initiate an accessibility scan by calling the following in your JavaScript Appium tests:
const settings = { apiKey: '<your-api-key-here>' }
const result = await driver.execute('mobile: axeScan', settings)
Full Example with UIAutomator2
const {remote} = require('webdriverio');
const wdOpts = {
hostname: process.env.APPIUM_HOST || 'localhost',
port: parseInt(process.env.APPIUM_PORT, 10) || 4723,
logLevel: 'info',
capabilities: {
platformName: 'Android',
'appium:automationName': 'AxeUiAutomator2',
'appium:deviceName': 'Android',
'appium:appPackage': 'com.android.settings',
'appium:appActivity': '.Settings',
}
}
async function runAccessibilityScan() {
const driver = await remote(wdOpts);
try {
const settings = { apiKey: '<your-api-key-here>' }
const result = await driver.execute('mobile: axeScan', settings)
} finally {
await driver.pause(1000);
await driver.deleteSession();
}
}
runAccessibilityScan().catch(console.error);
Full Example with XCUITest
const {remote} = require('webdriverio');
const wdOpts = {
hostname: process.env.APPIUM_HOST || 'localhost',
port: parseInt(process.env.APPIUM_PORT, 10) || 4723,
logLevel: 'info',
capabilities: {
platformName: 'iOS',
'appium:automationName': 'AxeXCUITest',
'appium:udid': '...', // xcrun simctl list | grep Booted
'appium:bundleId': 'com.dequesystems.axe-devtools-ios-sample-app'
}
}
async function runAccessibilityScan() {
const driver = await remote(wdOpts);
try {
const settings = { apiKey: '<your-api-key-here>' }
const result = await driver.execute('mobile: axeScan', settings)
} finally {
await driver.pause(1000);
await driver.deleteSession();
}
}
runAccessibilityScan().catch(console.error);