Test Example in Python

Link to Test Example in Python 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 Python

Initiate an accessibility scan by calling the following in your Python Appium tests:

settings = {}
settings['apiKey'] = "<your-api-key-here>"
result = self.driver.execute_script('mobile: axeScan', settings)

Full Example with UIAutomator2

from appium import webdriver
from appium.options.android import UiAutomator2Options
from appium.webdriver.appium_connection import AppiumConnection
import json

class AppiumPluginTest:

    def setup(self):
        success = True
        desired_caps = {}

        desired_caps['platformName'] = 'Android'
        desired_caps['automationName'] = 'AxeUiAutomator2'
        desired_caps['appPackage'] = "com.android.settings"
        desired_caps['appActivity'] = ".Settings"

        options = UiAutomator2Options().load_capabilities(desired_caps)
        self.driver = webdriver.Remote('http://localhost:4723', options=options)

    def runAccessibilityScan(self):
        settings = {}
        settings['apiKey'] = "<your-api-key-here>"
        return self.driver.execute_script('mobile: axeScan', settings)


demo = AppiumPluginTest()
demo.setup()

result = demo.runAccessibilityScan()

Full Example with XCUITest

from appium import webdriver
from appium.options.ios import XCUITestOptions
from appium.webdriver.appium_connection import AppiumConnection
import json

class AppiumPluginTest:

    def setup(self):
        success = True
        desired_caps = {}

        desired_caps['platformName'] = 'iOS'
        desired_caps['automationName'] = 'AxeXCUITest'
        desired_caps['bundleId'] = 'com.dequesystems.axe-devtools-ios-sample-app'
        desired_caps['udid'] = '...' # xcrun simctl list | grep Booted

        options = XCUITestOptions().load_capabilities(desired_caps)
        self.driver = webdriver.Remote('http://localhost:4723', options=options)

    def runAccessibilityScan(self):
        settings = {}
        settings['apiKey'] = "<your-api-key-here>"
        return self.driver.execute_script('mobile: axeScan', settings)


demo = AppiumPluginTest()
demo.setup()

result = demo.runAccessibilityScan()