"Bad capabilities. Specify either app or appTopLevelWindow to create a session" Error given by the WinApp driver

huangapple go评论73阅读模式
英文:

"Bad capabilities. Specify either app or appTopLevelWindow to create a session" Error given by the WinApp driver

问题

使用WinApp驱动进行桌面自动化时,我在下面的错误截图中遇到了问题。

"Bad capabilities. Specify either app or appTopLevelWindow to create a session" Error given by the WinApp driver

我用于启动WinApp驱动会话的源代码如下:

public void setupDesktopAutomation(String appName, String platformName, String deviceName) {

    try {

        Desktop desktop = Desktop.getDesktop();
        desktop.open(new File("D:\\Software\\Windows Application Driver\\WinApp\\WinAppDriver.exe"));
        
        DesiredCapabilities caps = new DesiredCapabilities();
        caps.setCapability("app", appName);
        caps.setCapability("platformName", platformName);
        caps.setCapability("deviceName", deviceName);
        windowsDriver = new WindowsDriver(new URL("http://127.0.0.1:4723/"), caps);
        windowsDriver.manage().wait(5000);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }

}

我对此进行了很多研究,发现Selenium版本4(我正在使用Selenium版本4.7.2)与最新的WinApp驱动不兼容。在网上有很多文章指出,为了使WinApp驱动正常工作,我们需要将Selenium版本降级到3.141.1。

  1. https://github.com/microsoft/WinAppDriver/issues/1774.
  2. https://github.com/microsoft/WinAppDriver/issues/1839

此外,我还发现在一些文章中,我们可以使用Selenium版本4,并通过Appium作为中间人连接到WinApp驱动。但这些文章没有显示如何实现这一点。请查看下面的文章。

  1. https://github.com/nightwatchjs/nightwatch/issues/3579

因此,我想知道在不降级Selenium版本的情况下,如何修改上面的源代码以成功启动WinApp驱动。

英文:

I am getting the below error screenshot when using the WinApp driver for the desktop automation.

"Bad capabilities. Specify either app or appTopLevelWindow to create a session" Error given by the WinApp driver

The source code I am using to initiate the WinApp driver session as below.

public void setupDesktopAutomation(String appName, String platformName, String deviceName) {

try {

    Desktop desktop = Desktop.getDesktop();
    desktop.open(new File("D:\\Software\\Windows Application Driver\\WinApp\\WinAppDriver.exe"));
    
    DesiredCapabilities caps = new DesiredCapabilities();
    caps.setCapability("app", appName);
    caps.setCapability("platformName", platformName);
    caps.setCapability("deviceName", deviceName);
    windowsDriver = new WindowsDriver(new URL("http://127.0.0.1:4723/"), caps);
    windowsDriver.manage().wait(5000);
} catch (Exception e) {
    throw new RuntimeException(e);
}

}

I did many research on this and found that the Selenium version 4 (I am using the Selenium Version 4.7.2) is not compatible with the latest WinApp driver. There are many articles found in the web that we need to downgrade the Selenium version to 3.141.1 in order to WinApp driver to work

  1. https://github.com/microsoft/WinAppDriver/issues/1774.
  2. https://github.com/microsoft/WinAppDriver/issues/1839

Also I found that in few articles that we can use Selenium Version 4 and still connect to the WinApp driver using the Appium as a middle man. But those articles does not shown how we can do this. Please check the below article.

  1. https://github.com/nightwatchjs/nightwatch/issues/3579

So I want to know without downgrading the selenium version, how I can modify the above source code to initiate the WinApp driver successfully.

答案1

得分: 1

Finally I was able to solve the problem of my own. Here are the steps.

  1. Download the Appium. - https://appium.io/downloads.html
  2. Install the downloaded Appium.
  3. Start the Appium server and give a host and port number - Here I have given as shown in below screenshot.
  4. You can use the below source code to connect to the Appium server and open the notepad application (In the URL section you have to give the correct host and port number as given in step 3, Also appname is the parameter where you can pass the application you want to open)
DesiredCapabilities caps = new DesiredCapabilities();
caps.setCapability("app", appName);
windowsDriver = new WindowsDriver(new URL("http://0.0.0.0:4723/wd/hub"), caps);

Pre-Requisite:

java.lang.RuntimeException:
org.openqa.selenium.SessionNotCreatedException: Could not start a new
session. Response code 500. Message: An unknown server-side error
occurred while processing the command. Original error:
WinAppDriver.exe has not been found in any of these locations:
C:\Program Files (x86)\Windows Application
Driver\WinAppDriver.exe,C:\Program Files\Windows Application
Driver\WinAppDriver.exe,C:\Program Files\Windows Application
Driver\WinAppDriver.exe. Is it installed?

I got the above error when initially execute the Appium driver, so I had manually downloaded WinApp driver to one of the above locations.

英文:

Finally I was able to solve the problem of my own. Here are the steps.

  1. Download the Appium. - https://appium.io/downloads.html
  2. Install the downloaded Appium.
  3. Start the Appium server and give a host and port number - Here I have given as shown in below screenshot.

"Bad capabilities. Specify either app or appTopLevelWindow to create a session" Error given by the WinApp driver

  1. You can use the below source code to connect to the Appium server and open the notepad application (In the URL section you have to give the correct host and port number as given in step 3, Also appname is the parameter where you can pass the application you want to open)

    DesiredCapabilities caps = new DesiredCapabilities();

    caps.setCapability("app", appName);

    windowsDriver = new WindowsDriver(new URL("http://0.0.0.0:4723/wd/hub"),
    caps);

Pre-Requisite:

> java.lang.RuntimeException:
> org.openqa.selenium.SessionNotCreatedException: Could not start a new
> session. Response code 500. Message: An unknown server-side error
> occurred while processing the command. Original error:
> WinAppDriver.exe has not been found in any of these locations:
> C:\Program Files (x86)\Windows Application
> Driver\WinAppDriver.exe,C:\Program Files\Windows Application
> Driver\WinAppDriver.exe,C:\Program Files\Windows Application
> Driver\WinAppDriver.exe. Is it installed?

I got the above error when initially execute the Appium driver, so I had manually downloaded WinApp driver to one of the above locations.

huangapple
  • 本文由 发表于 2023年2月27日 15:49:42
  • 转载请务必保留本文链接:https://go.coder-hub.com/75577921.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定