Test Example in Ruby

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

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

settings = { apiKey: '<your-api-key>' }
result =  @driver.execute_script 'axe:scan', settings

Example With Page Source

When Appium's page source API is incorporated into your tests, consider optimizing performance by passing it through the execute script method. While providing the page source is optional, we advise against it unless you are confident that the page source accurately reflects your application's current state and remains unmodified. For more precise results, it's recommended to refrain from passing the page source.

settings = { apiKey: '<your-api-key>' }
pageSource = @driver.page_source
result =  @driver.execute_script 'axe:scan', settings, pageSource

Full Example with UIAutomator2

require 'appium_lib_core'
require 'test/unit'
require 'json'

CAPABILITIES = {
  platformName: 'Android',
  automationName: 'uiautomator2',
  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 'axe:scan', 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: 'XCUITest',
  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 'axe:scan', settings
    puts JSON.pretty_generate(result)
  end
end