Exemple de test 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

N'oubliez pas de consulter le guide d'installation d'Appium avec axe DevTools Mobile complet si vous débutez, ou d'autres exemples d'axe DevTools Mobile pour Appium dans d'autres langues.

executeScript en C#

Lancez une analyse d'accessibilité en appelant ce qui suit dans vos tests C# Appium :

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

Exemple complet avec 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);
    }
}

Exemple complet avec 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);
    }
}