Test Example in Kotlin

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

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

val settings = mapOf("apiKey" to "<your-api-key-here>")
driver.executeScript("mobile: axeScan", settings)

Full Example with UIAutomator2

import io.appium.java_client.android.AndroidDriver
import io.appium.java_client.remote.AutomationName
import io.appium.java_client.remote.MobileCapabilityType
import io.appium.java_client.remote.MobilePlatform
import org.junit.Before
import org.junit.Test
import org.openqa.selenium.remote.DesiredCapabilities
import java.net.URL

class AppiumPluginTest {
    private lateinit var driver: AndroidDriver

    companion object {
        private const val DEFAULT_APPIUM_ADDRESS = "http://0.0.0.0:4723"

        fun makeDriver(): AndroidDriver {
            val capabilities = DesiredCapabilities()
            capabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, MobilePlatform.ANDROID)
            capabilities.setCapability(MobileCapabilityType.AUTOMATION_NAME, "AxeUiAutomator2")
            capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "Android Emulator")
            capabilities.setCapability("appium:appPackage", "com.android.settings")
            capabilities.setCapability("appium:appActivity", ".Settings")

            return AndroidDriver(URL(DEFAULT_APPIUM_ADDRESS), capabilities)
        }
    }

    @Before
    fun setup() {
        driver = makeDriver()
    }

    @Test
    fun test() {
        val settings = mapOf("apiKey" to "<your-api-key-here>")
        driver.executeScript("mobile: axeScan", settings)
    }
}

Full Example with XCUITest

import io.appium.java_client.ios.IOSDriver
import io.appium.java_client.remote.AutomationName
import io.appium.java_client.remote.MobileCapabilityType
import io.appium.java_client.remote.MobilePlatform
import org.junit.Before
import org.junit.Test
import org.openqa.selenium.remote.DesiredCapabilities
import java.net.URL

class AppiumPluginTest {
    private lateinit var driver: IOSDriver

    companion object {
        private const val DEFAULT_APPIUM_ADDRESS = "http://0.0.0.0:4723"

        fun makeDriver(): IOSDriver {
            val capabilities = DesiredCapabilities()
            capabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, MobilePlatform.IOS)
            capabilities.setCapability(MobileCapabilityType.AUTOMATION_NAME, "AxeXCUITest")
            capabilities.setCapability("appium:bundleId", "com.dequesystems.axe-devtools-ios-sample-app")
            capabilities.setCapability("appium:udid", "...") // xcrun simctl list | grep Booted

            return IOSDriver(URL(DEFAULT_APPIUM_ADDRESS), capabilities)
        }
    }

    @Before
    fun setup() {
        driver = makeDriver()
    }

    @Test
    fun test() {
        val settings = mapOf("apiKey" to "<your-api-key-here>")
        driver.executeScript("mobile: axeScan", settings)
    }
}