英文:
"Bad capabilities. Specify either app or appTopLevelWindow to create a session" Error given by the WinApp driver
问题
使用WinApp驱动进行桌面自动化时,我在下面的错误截图中遇到了问题。
我用于启动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。
- https://github.com/microsoft/WinAppDriver/issues/1774.
- https://github.com/microsoft/WinAppDriver/issues/1839
此外,我还发现在一些文章中,我们可以使用Selenium版本4,并通过Appium作为中间人连接到WinApp驱动。但这些文章没有显示如何实现这一点。请查看下面的文章。
因此,我想知道在不降级Selenium版本的情况下,如何修改上面的源代码以成功启动WinApp驱动。
英文:
I am getting the below error screenshot when using the WinApp driver for the desktop automation.
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
- https://github.com/microsoft/WinAppDriver/issues/1774.
- 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.
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.
- Download the Appium. - https://appium.io/downloads.html
- Install the downloaded Appium.
- Start the Appium server and give a host and port number - Here I have given as shown in below screenshot.
- 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.
- Download the Appium. - https://appium.io/downloads.html
- Install the downloaded Appium.
- Start the Appium server and give a host and port number - Here I have given as shown in below screenshot.
-
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论