Android Test Example with UiAutomator2 Driver

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

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 appium.options.android 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'] = "com.app.package.MainActivity"

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

        # 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()
demo.setup()

# <Navigate To Screen>
demo.runAccessibilityScan()

# <Navigate To Another Screen>
demo.runAccessibilityScan()