简体   繁体   English

Appium WinAppDriver 和 Selenium 4

[英]Appium WinAppDriver and Selenium 4

I am struggling to use get WinAppDriver to open an application, my maven imports are as follows:我正在努力使用 get WinAppDriver 打开一个应用程序,我的 maven 导入如下:

<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:但是,当我将 selenium 版本更改为:

<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?我可以打开应用程序,我不确定我是否遗漏了什么,有人可以帮忙吗?

You can try complying with the W3C standard for capabilities in which case you will need appium:app , appium:ms:experimental-webdriver and appium:automationName as capabilities and see if this helps.您可以尝试遵守 W3C 功能标准,在这种情况下,您将需要appium:appappium:ms:experimental-webdriverappium:automationName作为功能,看看这是否有帮助。 platformName is compliant with W3C so no change there. platformName符合 W3C,因此没有变化。 For more information you can refer to this有关更多信息,您可以参考

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.您能够让 WinAppDriver 打开 Selenium v3.141.59而不是 Selenium v4.6.0的应用程序的原因是 Appium java 客户端的主要版本 7 和 8 之间发生了一些重大变化。

As per the v7-to-v8-migration-guide from W3C specification compatibility perspective:根据从 W3C 规范兼容性角度来看的v7-to-v8-migration-guide

  • Java client now supports Selenium 4, which also means it is strictly W3C compliant. Java 客户端现在支持 Selenium 4,这也意味着它严格符合 W3C。 Old JWP-based servers are not supported anymore, and it won't be possible to use the new client version with them.不再支持旧的基于 JWP 的服务器,并且无法与它们一起使用新的客户端版本。 Capabilities that enforce the usage of JWP protocol on Appium drivers don't have any effect anymore.强制在 Appium 驱动程序上使用 JWP 协议的功能不再有任何影响。
  • The recommended way to provide capabilities for driver creation is to use specific option builders inherited from BaseOptions class .为驱动程序创建提供功能的推荐方法是使用从BaseOptions class继承的特定选项构建器。 For example XCUITestOptions to create a XCUITest driver instance or UiAutomator2Options to create an UiAutomator2 driver instance.例如,用于创建XCUITest驱动程序实例的XCUITestOptions或用于创建 UiAutomator2 驱动程序实例的 UiAutomator2Options。 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.如果您的驱动程序没有特定于驱动程序的选项 class,则可以使用 BaseOptions 构建器作为基础 class 来定义您的功能,或者请求驱动程序开发人员添加一个。 Do not use DesiredCapabilities class for this purpose in W3C context.不要在 W3C 上下文中为此目的使用 DesiredCapabilities class。 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:此外,在讨论中Unable to Initiate Session with WinAppDriver @Appium maintainer @KazuCocoa提到:

The WinAppDriver requires selenium v3 based client for now since Selenium v4 requires W3C spec protocol that is not supported by WinAppDriver yet. WinAppDriver 目前需要基于 selenium v3 的客户端,因为 Selenium v4 需要 WinAppDriver 尚不支持的 W3C 规范协议。

Further in the discussion Support for Selenium 4 @pm90pl confirmed:在讨论中进一步支持 Selenium 4 @pm90pl确认:

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.因此,当前版本不兼容 W3C WebDriver 标准,这使得它与 Selenium 不兼容 4. WAD 没有明确的路线图,它不是开源的,所以你必须自己处理。 Upgrading Selenium without checking WAD compatibility was a mistake.在不检查 WAD 兼容性的情况下升级 Selenium 是一个错误。 Sorry.对不起。


Conclusion结论

The only viable option to execute the WinAppDriver based test is to backport to Selenium v3.141.59执行基于 WinAppDriver 的测试的唯一可行选项是向后移植到Selenium v3.141.59

As per github discussion on WinAppDriver:根据 github 关于 WinAppDriver 的讨论:

The WinAppDriver requires selenium v3 based client for now since Selenium v4 requires W3C spec protocol that is not supported by WinAppDriver yet. WinAppDriver 目前需要基于 selenium v3 的客户端,因为 Selenium v4 需要 WinAppDriver 尚不支持的 W3C 规范协议。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM