Auto Scan Code Examples with UIAutomator2
Not for use with personal data
JavaScript (WebDriverIO)
const driver = await remote({
capabilities: {
platformName: 'Android',
'appium:automationName': 'AxeUiAutomator2',
'appium:app': '/path/to/app.apk',
}
});
// Start auto scan
await driver.executeScript('mobile: axeStartAutoScanSession', [{
axeMobileApiKey: 'your-api-key'
}]);
// Run your test — every screen change is captured
await driver.$('~Login').click();
await driver.$('~Dashboard').waitForDisplayed();
await driver.$('~Settings').click();
// Stop auto scan and get results
const results = await driver.executeScript('mobile: axeStopAutoScanSession', []);
console.log(`Files processed: ${results.processedCount}/${results.fileCount}`);
console.log(`Results saved to: ${results.localDirectory}`);
await driver.deleteSession();Python
from appium import webdriver
from appium.options.android import UiAutomator2Options
options = UiAutomator2Options()
options.platform_name = 'Android'
options.automation_name = 'AxeUiAutomator2'
options.app = '/path/to/app.apk'
driver = webdriver.Remote('http://localhost:4723', options=options)
# Start auto scan
driver.execute_script('mobile: axeStartAutoScanSession', {
'axeMobileApiKey': 'your-api-key'
})
# Run your test
driver.find_element('accessibility id', 'Login').click()
driver.find_element('accessibility id', 'Dashboard')
driver.find_element('accessibility id', 'Settings').click()
# Stop auto scan and get results
results = driver.execute_script('mobile: axeStopAutoScanSession')
print(f"Files processed: {results['processedCount']}/{results['fileCount']}")
print(f"Results saved to: {results['localDirectory']}")
driver.quit()Ruby
require 'appium_lib'
caps = {
platformName: 'Android',
'appium:automationName': 'AxeUiAutomator2',
'appium:app': '/path/to/app.apk'
}
driver = Appium::Driver.new({ caps: caps, appium_lib: { server_url: 'http://localhost:4723' } }, true)
driver.start_driver
# Start auto scan
driver.execute_script('mobile: axeStartAutoScanSession', {
'axeMobileApiKey' => 'your-api-key'
})
# Run your test
driver.find_element(:accessibility_id, 'Login').click
driver.find_element(:accessibility_id, 'Dashboard')
driver.find_element(:accessibility_id, 'Settings').click
# Stop auto scan and get results
results = driver.execute_script('mobile: axeStopAutoScanSession')
puts "Files processed: #{results['processedCount']}/#{results['fileCount']}"
puts "Results saved to: #{results['localDirectory']}"
driver.quit_driverJava
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.android.options.UiAutomator2Options;
import java.net.URL;
import java.util.Map;
import java.util.HashMap;
UiAutomator2Options options = new UiAutomator2Options()
.setPlatformName("Android")
.setAutomationName("AxeUiAutomator2")
.setApp("/path/to/app.apk");
AndroidDriver driver = new AndroidDriver(new URL("http://localhost:4723"), options);
// Start auto scan
Map<String, Object> scanArgs = new HashMap<>();
scanArgs.put("axeMobileApiKey", "your-api-key");
driver.executeScript("mobile: axeStartAutoScanSession", scanArgs);
// Run your test
driver.findElement(AppiumBy.accessibilityId("Login")).click();
driver.findElement(AppiumBy.accessibilityId("Dashboard"));
driver.findElement(AppiumBy.accessibilityId("Settings")).click();
// Stop auto scan and get results
Map<String, Object> results = (Map<String, Object>)
driver.executeScript("mobile: axeStopAutoScanSession");
System.out.println("Files processed: " + results.get("processedCount") +
"/" + results.get("fileCount"));
System.out.println("Results saved to: " + results.get("localDirectory"));
driver.quit();Kotlin
import io.appium.java_client.android.AndroidDriver
import io.appium.java_client.android.options.UiAutomator2Options
import io.appium.java_client.AppiumBy
import java.net.URL
val options = UiAutomator2Options()
.setPlatformName("Android")
.setAutomationName("AxeUiAutomator2")
.setApp("/path/to/app.apk")
val driver = AndroidDriver(URL("http://localhost:4723"), options)
// Start auto scan
val scanArgs = mapOf("axeMobileApiKey" to "your-api-key")
driver.executeScript("mobile: axeStartAutoScanSession", scanArgs)
// Run your test
driver.findElement(AppiumBy.accessibilityId("Login")).click()
driver.findElement(AppiumBy.accessibilityId("Dashboard"))
driver.findElement(AppiumBy.accessibilityId("Settings")).click()
// Stop auto scan and get results
val results = driver.executeScript("mobile: axeStopAutoScanSession") as Map<String, Any>
println("Files processed: ${results["processedCount"]}/${results["fileCount"]}")
println("Results saved to: ${results["localDirectory"]}")
driver.quit()