Search code examples
javaseleniumappiumwinappdriverselenium4

Appium WinAppDriver and Selenium 4


I am struggling to use get WinAppDriver to open an application, my maven imports are as follows:

<dependencies>
    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-java</artifactId>
        <version>4.6.0</version>
    </dependency>
    <dependency>
        <groupId>io.cucumber</groupId>
        <artifactId>cucumber-java</artifactId>
            <version>7.9.0</version>
    </dependency>
    <dependency>
        <groupId>io.cucumber</groupId>
        <artifactId>cucumber-testng</artifactId>
        <version>7.9.0</version>
        <scope>compile</scope>
    </dependency>
    <dependency>
        <groupId>com.github.javafaker</groupId>
        <artifactId>javafaker</artifactId>
        <version>1.0.2</version>
    </dependency>
    <dependency>
        <groupId>org.assertj</groupId>
        <artifactId>assertj-core</artifactId>
        <version>3.23.1</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>io.appium</groupId>
        <artifactId>java-client</artifactId>
        <version>8.2.1</version>
    </dependency>

I am opening the application with the following code:

  WindowsDriver adminApp = null;
    DesiredCapabilities winCap = new DesiredCapabilities();
    winCap.setCapability("app", "C:\\Program Files\\Traka\\Traka Web Admin\\TrakaWebAdmin.exe");
    winCap.setCapability("ms:experimental-webdriver", true);
    winCap.setCapability("platformName", "windows");
    winCap.setCapability("automationName", "windows");
    adminApp = new WindowsDriver(new URL("http://127.0.0.1:4723/"), winCap);

every time I run this I get the following error:

{"status":100,"value":
 {"error":"invalid argument","message":"Bad capabilities. Specify either app or appTopLevelWindow to create a session"}}

However when I change my selenium version to:

<dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-java</artifactId>
        <version>3.141.59</version>
    </dependency>

I can open the application, I am not sure if I am missing anything, can anyone help?


Solution

  • The reason you are able to get the WinAppDriver to open an application with Selenium v3.141.59 but not with Selenium v4.6.0 is due to some major changes between major versions 7 and 8 of Appium java client.

    As per the v7-to-v8-migration-guide from W3C specification compatibility perspective:

    • Java client now supports Selenium 4, which also means it is strictly W3C compliant. Old JWP-based servers are not supported anymore, and it won't be possible to use the new client version with them. Capabilities that enforce the usage of JWP protocol on Appium drivers don't have any effect anymore.
    • The recommended way to provide capabilities for driver creation is to use specific option builders inherited from BaseOptions class. For example XCUITestOptions to create a XCUITest driver instance or UiAutomator2Options to create an UiAutomator2 driver instance. If there is no driver-specific options class for your driver then either use BaseOptions builder as the base class to define your capabilities or request driver developers to add one. Do not use DesiredCapabilities class for this purpose in W3C context. Check unit tests for more examples on how to build driver options.

    Moreover in the discussion Unable to Initiate Session with WinAppDriver @Appium maintainer @KazuCocoa mentioned that:

    The WinAppDriver requires selenium v3 based client for now since Selenium v4 requires W3C spec protocol that is not supported by WinAppDriver yet.

    Further in the discussion Support for Selenium 4 @pm90pl confirmed:

    Yeah. So, the current version is not compatible with W3C WebDriver standard what makes it incompatible with Selenium 4. There is no clear roadmap for WAD and it's not open source so you have to deal it on your own. Upgrading Selenium without checking WAD compatibility was a mistake. Sorry.


    Conclusion

    The only viable option to execute the WinAppDriver based test is to backport to Selenium v3.141.59