Ejemplo de prueba en C#

This page is not available in the language you requested. You have been redirected to the English version of the page.
Link to this page copied to clipboard
Not for use with personal data

Asegúrate de consultar la completa Guía de configuración de Appium con axe DevTools Mobile si recién estás comenzando, o más ejemplos de axe DevTools Mobile para Appium en otros idiomas.

executeScript en C#

Inicie un análisis de accesibilidad llamando lo siguiente en sus pruebas de C# Appium:

axeSettings = new Dictionary<string, string>();
axeSettings.Add("apiKey", "<your-api-key>");
var result = _driver.ExecuteScript("mobile: axeScan", axeSettings);

Ejemplo completo con 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() {
            // Please note "Axe" at the beginning of the driver's Automation Name
            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);
    }
}

Ejemplo completo con 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() {
            // Please note "Axe" at the beginning of the driver's Automation Name
            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);
    }
}