Testbeispiel in Java

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.

ausführenScript in Java

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

Map<String, String> settings = ImmutableMap.of("apiKey", "<your-api-key-here>");
driver.executeScript("mobile: axeScan", settings);

Vollständiges Beispiel mit UIAutomator2

import com.google.common.collect.ImmutableMap;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.remote.AutomationName;
import io.appium.java_client.remote.MobileCapabilityType;
import io.appium.java_client.remote.MobilePlatform;

import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.remote.DesiredCapabilities;

import java.net.MalformedURLException;
import java.net.URL;
import java.util.Map;

public class AppiumPluginTest {
    AndroidDriver driver;

    AndroidDriver makeDriver() throws MalformedURLException {
        DesiredCapabilities capabilities = new DesiredCapabilities();
        capabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, MobilePlatform.ANDROID);
        // Please note "Axe" at the beginning of the driver's Automation Name
        capabilities.setCapability(MobileCapabilityType.AUTOMATION_NAME, "AxeUiAutomator2");
        capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "Android Emulator");
        capabilities.setCapability("appium:appPackage", "com.android.settings");
        capabilities.setCapability("appium:appActivity", ".Settings");

        String DEFAULT_APPIUM_ADDRESS = "http://0.0.0.0:4723/";
        return new AndroidDriver(new URL(DEFAULT_APPIUM_ADDRESS), capabilities);
    }

    @Before
    public void setup() throws MalformedURLException {
        driver = makeDriver();
    }

    @Test
    public void test() {
        Map<String, String> settings = ImmutableMap.of("apiKey", "<your-api-key-here>");
        driver.executeScript("mobile: axeScan", settings);
    }
}

Vollständiges Beispiel mit XCUITest

import com.google.common.collect.ImmutableMap;
import io.appium.java_client.ios.IOSDriver;
import io.appium.java_client.remote.AutomationName;
import io.appium.java_client.remote.MobileCapabilityType;
import io.appium.java_client.remote.MobilePlatform;

import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.remote.DesiredCapabilities;

import java.net.MalformedURLException;
import java.net.URL;
import java.util.Map;


public class AppiumPluginTest {
    IOSDriver driver;

    IOSDriver makeDriver() throws MalformedURLException {
        DesiredCapabilities capabilities = new DesiredCapabilities();
        capabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, MobilePlatform.IOS);
        // Please note "Axe" at the beginning of the driver's Automation Name
        capabilities.setCapability(MobileCapabilityType.AUTOMATION_NAME, "AxeXCUITest");
        capabilities.setCapability("appium:bundleId", "com.dequesystems.axe-devtools-ios-sample-app");
        capabilities.setCapability("appium:udid", "..."); // xcrun simctl list | grep Booted

        String DEFAULT_APPIUM_ADDRESS = "http://0.0.0.0:4723/";
        return new IOSDriver(new URL(DEFAULT_APPIUM_ADDRESS), capabilities);
    }

    @Before
    public void setup() throws MalformedURLException {
        driver = makeDriver();
    }

    @Test
    public void test() {
        Map<String, String> settings = ImmutableMap.of("apiKey", "<your-api-key-here>");
        driver.executeScript("mobile: axeScan", settings);
    }
}