1

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?

  • Selenium Version: 4.1.0
  • Chrome Driver: 100.0 (latest)

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

user110009
  • 25
  • 5

1 Answers1

1

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

titusfortner
  • 4,099
  • 2
  • 15
  • 29
  • I have made few changes, which I could understand but yet I am facing the same. I have updated the above under tried code along with the screenshots. In the images you can see that it is using W3C capabilities and the Appium server is called on sauce labs. I am guessing would be an issue with the chromium driver? But it is weird cause locally and on browsers the newly added features of Selenium 4 are working absolutely fine but not on the device (to mention I am looking at emulators and not real devices on sauce labs). @titusfortner – user110009 Apr 11 '22 at 13:56
  • Send me a link to the test and I can check what Sauce is seeing. – titusfortner Apr 11 '22 at 17:40
  • Oh, just saw you are trying to open a new window. I'm not sure Appium supports that command. I'll ask, but you might need to adjust your test. – titusfortner Apr 11 '22 at 17:47
  • Yes, I got confirmation from the Appium team. I updated my answer to indicate that the command isn't supported, yet. – titusfortner Apr 11 '22 at 18:53
  • Ooh, I see. This issue definitely bought something good out of it. I will keep exploring the new features of selenium 4 using appium and will buzz you in case anything :). Thank you for all your help. @titusfortner – user110009 Apr 14 '22 at 07:45
  • I am facing another issue on saucelabs (appium) for screenshots, for getScreenshotAs method. Could you please have a look at [link](https://stackoverflow.com/questions/71871228/org-openqa-selenium-webdriverexception-for-appium-on-selenium4-for-getscreenshot) @titusfortner – user110009 Apr 14 '22 at 11:58