Testbeispiel in 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

Schauen Sie sich unbedingt die vollständige Appium-Setup-Anleitung mit axe DevTools Mobile an, wenn Sie gerade erst anfangen, oder weitere Beispiele für axe DevTools Mobile für Appium in anderen Sprachen.

ScriptAusführen in C#

Starten Sie einen Zugänglichkeitsscan, indem Sie in Ihren C#-Appium-Tests Folgendes aufrufen:

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

Vollständiges Beispiel mit 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);
    }
}

Vollständiges Beispiel mit 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);
    }
}