Skip to content

4 WindowsApps

Martin Großmann edited this page Jun 20, 2024 · 2 revisions

WinAppDriver support

Please note: Currently we only support WinAppDriver up to Appium Connector version 2.2!

The Appium connector also supports automation of Windows application using the WindowsDriver in two setup scenarios.

  • Using an Appium-Server
  • Using a WinAppServer

Using WinAppDriver

The WinAppDriver is like a Selenium server for Windows applications. You can download it from the official project website or just install it via. chocolatey

choco install winappdriver

Before you are able to use it, you should make sure:

  • That the Windows Operating System runs in Development Mode.
  • The WinAppDriver able to run.
"C:\Program Files (x86)\Windows Application Driver\WinAppDriver.exe"

Windows Application Driver listening for requests at: http://127.0.0.1:4723/
Press ENTER to exit.

You can customize the connection using Properties

Starting an application

You can start applications in several ways:

  • Start applications by the executable path.
  • Start drivers for the Windows Desktop.
  • Start drivers from known application window title.
  • Start application from internal application id (Documentation unknown)

Start applications from path

The application path gets translated to the application id and also sets the working directory based on its parent.

WinAppDriverRequest appRequest = new WinAppDriverRequest();
appRequest.setApplicationPath("C:\\Program Files (x86)\\Application\\Application.exe");

NOTE: Some applications require their working directory set to the parent of the application binary to run properly.

For example: C:\\Program Files (x86)\\Application\\Application.exe needs to run in C:\\Program Files (x86)\\Application. When setting the application path, the WinAppDriverRequests tries to detect the parent directory by using Java Path.getParent(), but this seems to be buggy when using Windows paths in Posix environments. Therefore, we've implemented a workaround to detect the base directory by using basic regular expressions with / and \\ delimiters.

Start a Desktop driver

WinAppDriverRequest appRequest = new WinAppDriverRequest();
appRequest.setDesktopApplication();

Start driver from known window title

This will try to initialize the driver by an already opened application identified by its window title. Otherwise, it will try to start by given application id.

WinAppDriverRequest appRequest = new WinAppDriverRequest();
appRequest.reuseApplicationByWindowTitle("My App");
appRequest.setApplicationPath("C:\\Program Files (x86)\\Application\\Application.exe");

Start applications from application id

Starting the application from application id is currently unknown. However, this application id starts the default calculator app.

WinAppDriverRequest appRequest = new WinAppDriverRequest();
appRequest.setApplication("Microsoft.WindowsCalculator_8wekyb3d8bbwe!App");

Retrieving element selectors

The WinAppDriver project provides a binary release of tool named UIRecorder for retrieving element selectors xPath by hovering and focusing elements.

Find UiElements

Most of the applications support finding elements using AutomationId attribute selector.

PreparedLocator automationLocator = LOCATE.prepare("//*[@AutomationId=\"%s\"]");
UiElement num1Btn = find(automationLocator.with("num1Button"));

Accessing the native WindowsDriver API

All features of the WindowsDriver implementation are hidden by the WebDriver by default. To retrieve the raw WindowsDriver, you can unwrap it via. WebDriverManager.

Optional<WindowsDriver> optionalWindowsDriver = WEB_DRIVER_MANAGER.unwrapWebDriver(appDriver, WindowsDriver.class);

optionalWindowsDriver.ifPresent(windowsDriver -> {
    // Native API access here
});

Closing applications

The application will automatically be closed, when WebDriver.quit() gets called managed by Testerra on session end. But that closes the application's window which doesn't mean that the application is forced to quit. It could still be opened as a system service available by System tray icons.

There is an experimental feature to force quit an application: https://github.com/Microsoft/WinAppDriver/issues/159

Anyway, if you want to prevent Testerra from closing your WinAppDriver, just configure it on the WinAppDriverRequest.

appRequest.setShutdownAfterTest(false);
appRequest.setShutdownAfterExecution(false);

Properties

The WinAppDriver implementation provides the following properties.

Property default Description
tt.winapp.server.url http://localhost:4723/ URL of the WinAppDriver or Appium / Selenium Grid ending on "wd/hub"
tt.winapp.reuse.timeout.seconds 2 Timeout for finding reusable applications.
tt.winapp.startup.timeout.seconds 8 Timeout for general driver startup.

Troubleshooting

Symptom: Application forget settings after restart

  • Solution: Try to set the working directory manually.

Symptom: Elements are not interactable on remote WinAppDriver

  • Reason: When closing RDP connections, the Desktop gets non-interactable as default behaviour.
  • Solution: You can use VNC instead or configure your RDP to keep sessions active. More information can be found here: https://github.com/microsoft/WinAppDriver/issues/1510

Symptom: Non-interactable elements on non-focused windows

  • Reason: Some applications get minimized when they loose focus.
  • Solution: Try to bring the window to the front by calling webDriver.manage().window().setPosition(new Point(0,0));