Test Example in JavaScript

Link to Test Example in JavaScript copied to clipboard
Free Trial

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('axe:scan', settings)

Example With Page Source

When Appium's page source API is incorporated into your tests, consider optimizing performance by passing it through the execute script method. While providing the page source is optional, we advise against it unless you are confident that the page source accurately reflects your application's current state and remains unmodified. For more precise results, it's recommended to refrain from passing the page source.

const settings = { apiKey: '<your-api-key-here' }
const pageSource = await driver.getPageSource()
const result = await driver.execute('axe:scan', settings, pageSource)

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': 'UiAutomator2',
    '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('axe:scan', 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': 'XCUITest',
    '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('axe:scan', settings)
 
  } finally {
    await driver.pause(1000);
    await driver.deleteSession();
  }
}

runAccessibilityScan().catch(console.error);