Testbeispiel in JavaScript

This page is not available in the language you requested. You have been redirected to the English version of the page.
Link to this page copied to clipboard
Not for use with personal data

Schauen Sie sich unbedingt die vollständige Appium-Setup-Anleitung mit axe DevTools Mobile an, wenn Sie gerade erst anfangen, oder weitere Beispiele für axe DevTools Mobile für Appium in anderen Sprachen.

executeScript in JavaScript

Starten Sie einen Zugänglichkeitsscan, indem Sie in Ihren JavaScript-Appium-Tests Folgendes aufrufen:

const settings = { apiKey: '<your-api-key-here>' }
const result = await driver.execute('mobile: axeScan', settings)

Vollständiges Beispiel mit 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',
    // Please note "Axe" at the beginning of the driver's Automation Name
    '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);

Vollständiges Beispiel mit 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',
    // Please note "Axe" at the beginning of the driver's Automation Name
    '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);