Test Example in Ruby
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 Ruby
Initiate an accessibility scan by calling the following in your Ruby Appium tests:
settings = { apiKey: '<your-api-key>' }
result = @driver.execute_script 'mobile: axeScan', settings
Full Example with UIAutomator2
require 'appium_lib_core'
require 'test/unit'
require 'json'
CAPABILITIES = {
platformName: 'Android',
automationName: 'AxeUiAutomator2',
deviceName: 'Android',
appPackage: 'com.android.settings',
appActivity: '.Settings',
}
SERVER_URL = 'http://localhost:4723'
class AppiumPluginTest < Test::Unit::TestCase
def setup
@core = ::Appium::Core.for capabilities: CAPABILITIES
@driver = @core.start_driver server_url: SERVER_URL
end
def teardown
@driver&.quit
end
def runAccessibilityScan
settings = { apiKey: '<your-api-key-here>' }
result = @driver.execute_script 'mobile: axeScan', settings
puts JSON.pretty_generate(result)
end
end
Full Example with XCUITest
require 'appium_lib_core'
require 'test/unit'
require 'json'
CAPABILITIES = {
platformName: 'iOS',
automationName: 'AxeXCUITest',
bundleId: 'com.dequesystems.axe-devtools-ios-sample-app',
udid: '...' # xcrun simctl list | grep Booted
}
SERVER_URL = 'http://localhost:4723'
class AppiumPluginTest < Test::Unit::TestCase
def setup
@core = ::Appium::Core.for capabilities: CAPABILITIES
@driver = @core.start_driver server_url: SERVER_URL
end
def teardown
@driver&.quit
end
def runAccessibilityScan
settings = { apiKey: '<your-api-key>' }
result = @driver.execute_script 'mobile: axeScan', settings
puts JSON.pretty_generate(result)
end
end