Test Example in C#
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 C#
Initiate an accessibility scan by calling the following in your C# Appium tests:
axeSettings = new Dictionary<string, string>();
axeSettings.Add("apiKey", "<your-api-key>");
var result = _driver.ExecuteScript("mobile: axeScan", axeSettings);
Full Example with UIAutomator2
using OpenQA.Selenium;
using OpenQA.Selenium.Appium;
using OpenQA.Selenium.Appium.Android;
using OpenQA.Selenium.Appium.Enums;
namespace appiumtest;
public class Tests
{
private AndroidDriver _driver;
private Dictionary<string, string> axeSettings;
public void setApiKey() {
axeSettings = new Dictionary<string, string>();
axeSettings.Add("apiKey", "<your-api-key>");
}
[OneTimeSetUp]
public void SetUp()
{
setApiKey();
var serverUri = new Uri(Environment.GetEnvironmentVariable("APPIUM_HOST") ?? "http://localhost:4723/");
var driverOptions = new AppiumOptions() {
AutomationName = "AxeUiAutomator2",
PlatformName = "Android",
};
driverOptions.AddAdditionalAppiumOption("appPackage", "com.android.settings");
driverOptions.AddAdditionalAppiumOption("appActivity", ".Settings");
driverOptions.AddAdditionalAppiumOption("noReset", true);
_driver = new AndroidDriver(serverUri, driverOptions, TimeSpan.FromSeconds(180));
_driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(10);
}
[OneTimeTearDown]
public void TearDown()
{
_driver.Dispose();
}
[Test]
public void Test()
{
var result = _driver.ExecuteScript("mobile: axeScan", axeSettings);
}
}
Full Example with XCUITest
using OpenQA.Selenium;
using OpenQA.Selenium.Appium;
using OpenQA.Selenium.Appium.iOS;
namespace appiumtest;
public class AppiumPluginTest
{
private IOSDriver _driver;
private Dictionary<string, string> axeSettings;
public void setApiKey() {
axeSettings = new Dictionary<string, string>();
axeSettings.Add("apiKey", "<your-api-key>");
}
[OneTimeSetUp]
public void SetUp()
{
setApiKey();
var serverUri = new Uri(Environment.GetEnvironmentVariable("APPIUM_HOST") ?? "http://localhost:4723/");
var driverOptions = new AppiumOptions() {
AutomationName = "AxeXCUITest",
PlatformName = "iOS",
};
driverOptions.AddAdditionalAppiumOption("bundleId", "com.dequesystems.axe-devtools-ios-sample-app");
driverOptions.AddAdditionalAppiumOption("udid", ""); // on Mac terminal: xcrun simctl list | grep Booted
_driver = new IOSDriver(serverUri, driverOptions, TimeSpan.FromSeconds(180));
_driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(10);
}
[OneTimeTearDown]
public void TearDown()
{
_driver.Dispose();
}
[Test]
public void Test()
{
var result = _driver.ExecuteScript("mobile: axeScan", axeSettings);
}
}