Android Test Example with UiAutomator2 Driver

Link to Android Test Example with UiAutomator2 Driver copied to clipboard
Free Trial

Be sure to checkout the full Appium setup guide with axe DevTools Mobile if you're just getting started.

UiAutomator2 Driver Example with Python Tests

While the below example is written in Python, the logic is transferable to other Appium client libraries.

from appium import webdriver
from import UiAutomator2Options
from appium.webdriver.appium_connection import AppiumConnection

class DemoWithAxeDevToolsMobile:

    def setup(self):
        success = True
        desired_caps = {}
        # Add your required capabilities for testing:
        desired_caps['platformName'] = 'Android'
        desired_caps['automationName'] = 'UiAutomator2'
        desired_caps['appActivity'] = ""

        # Add axe DevTools Mobile required capabilities for testing:
        desired_caps['appPackage'] = ""

        # Initialize Appium Server Connection
        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('axe:scan', settings)

demo = DemoWithAxeDevToolsMobile()

# <Navigate To Screen>

# <Navigate To Another Screen>