appiumsaucelabsselenium4desiredcapabilities

org.openqa.selenium.UnsupportedCommandException for appium (devices) for sauce labs


I am trying to upgrade from Selenium 3 to Selenium 4. The capabilities and everything works fine for all the browsers remotely on sauce labs and works well even on local but when it comes to devices(Android Ipad/Mobile and iOS Ipad/Mobile) I am getting org.openqa.selenium.UnsupportedCommandException. Can someone help out?

Capabilities

else if (!BaseTest.isLocal && BaseTest.Devices) {
DesiredCapabilities capabilities = new DesiredCapabilities();
        capabilities.setCapability("appiumVersion", "1.17.1");
        capabilities.setCapability("deviceOrientation", "portrait");
        capabilities.setCapability("browserName", browser);
        capabilities.setCapability("browserVersion", version);
        capabilities.setCapability("platformName", os);
        capabilities.setCapability("seleniumVersion", "4.1.0");
        capabilities.setCapability("deviceName", devicename);
        capabilities.setCapability("platformVersion", platformversion);
        capabilities.setCapability("name", methodName);
        capabilities.setCapability("autoAcceptAlerts", "true");
        System.out.println("pop-up alerts disabled for IOS");

        if (browser.toLowerCase().contains("chrome")) {
            ChromeOptions options = new ChromeOptions();
            options.addArguments("disable-translate");
            options.addArguments("disable-translate-new-ux");
            capabilities.setCapability(ChromeOptions.CAPABILITY, options);
        }

        if (buildTag != null) {
            capabilities.setCapability("build", buildTag);
        }

        // Launch remote browser and set it as the current thread
        webDriver.set(new RemoteWebDriver(
                new URL("https://" + username + ":" + accesskey + "@ondemand.saucelabs.com:443/wd/hub"),
                capabilities));

Code

    private ThreadLocal<WebDriver> webDriver = new ThreadLocal<WebDriver>();
     public WebDriver getWebDriver() {
    if (!BaseTest.isLocal) {
        return webDriver.get();
    } else {
        return localWebDriver;
    }
}

Error

FAILED: Selenium4("Chrome", "latest-1", "Android", "7.1", "Samsung Galaxy Tab A 10 GoogleAPI Emulator", public void com.dell.tnt.tests.WFTTests.Selenium_4_Test.Selenium4(java.lang.String,java.lang.String,java.lang.String,java.lang.String,java.lang.String,java.lang.reflect.Method) throws java.lang.InterruptedException,com.dell.tnt.exceptions.OfferNotFoundException,java.io.IOException,java.lang.NullPointerException,java.lang.IndexOutOfBoundsException,java.lang.ArrayIndexOutOfBoundsException) org.openqa.selenium.UnsupportedCommandException: The URL '/wd/hub/session/XXXXXXXX-XXXX-XXXX-XXXX-XXXXf7ad4561/window/new' did not map to a valid resource

[ErrorImage][1]

Tried Version:

    // Mobile Devices
        MutableCapabilities caps = new MutableCapabilities();
        caps.setCapability("platformName", os);
        caps.setCapability("deviceOrientation", "portrait");
        caps.setCapability("browserName", browser);
        caps.setCapability("appium:deviceName", devicename);
        caps.setCapability("appium:platformVersion", platformversion);
        MutableCapabilities sauceOptions = new MutableCapabilities();
        sauceOptions.setCapability("name", methodName);
        sauceOptions.setCapability("appiumVersion", "1.17.1");
        caps.setCapability("sauce:options", sauceOptions);

        if (buildTag != null) {
            caps.setCapability("build", buildTag);
        }

        // Launch remote browser and set it as the current thread
        webDriver.set(new RemoteWebDriver(
                new URL("https://" + username + ":" + accesskey + "@ondemand.saucelabs.com:443" + "/wd/hub"),
                caps));

**Error Error1

Saucelab: Saucelab


Solution

  • UPDATE: I got caught up in making sure settings were giving you a valid w3c session, which is required for that command to work in Desktop tests.

    Apparently the issue is that Appium does not have the window/new route supported at all right now. The Appium team has been made aware of it, and they'll get it added for a future release (and then it will only work on Android, not iOS). Appium issue: https://github.com/appium/appium/issues/16749


    So a few things here.

    For mobile browsers, you can use Selenium code locally, but your code is getting sent to an Appium server not a Selenium server on Sauce Labs VMs/Devices. It is expecting to see valid w3c compliant capabilities with Selenium 4.

    For w3c & Selenium 4 everything should theoretically be using the browser options class directly; no DesiredCapabilities, just ChromeOptions, etc.

    As for what capabilities are available on Sauce and how they get used, I recently updated this documentation, so it should be up to date: https://docs.saucelabs.com/dev/test-configuration-options/

    A good way to start is with using the Sauce Labs Platform Configurator to get your baseline: https://saucelabs.com/platform/platform-configurator Note that this is for using Selenium code, not Appium code. Also, this is for emulator/simulator code. Real devices are similar just with a different device name. Finally it uses MutableCapabilities instead of Browser Options classes because that was easier to generate on the back end not because it is preferred.

    It'll look something like this:

    MutableCapabilities caps = new MutableCapabilities();
    caps.setCapability("platformName", "iOS");
    caps.setCapability("browserName", "Safari");
    caps.setCapability("appium:deviceName", "iPhone Simulator");
    caps.setCapability("appium:platformVersion", "15.4");
    MutableCapabilities sauceOptions = new MutableCapabilities();
    sauceOptions.setCapability("appiumVersion", "1.22.3");
    caps.setCapability("sauce:options", sauceOptions);
    

    Finally, you should update your endpoint, as the old endpoint has some issues with w3c + Real Devices: https://docs.saucelabs.com/basics/data-center-endpoints/#us-west-data-center