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
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.
Finally I was able to solve the problem of my own. Here are the steps.
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.