Tips to integrate WinAppDriver/YWinAppDriver with nodejs/JavaScript webdriver client

Canhua Li
3 min readNov 29, 2020

--

This applies to both WinAppDriver and YWinAppDriver.

WinAppDriver is supported by Microsoft officially and YWinAppDriver is an open-source WinAppDriver implementation I created.

  1. Set implicit timeout

Implicit timeout is useful when WinAppDriver is looking for element/elements. It waits until timeout before returning not found.

It reduces the interaction between client and WinAppDriver, so it reduces the logs too

browser.setTimeout({ implicit: 5000 });

2. Remove appium from your package dependencies

No matter WinAppDriver or YWinAppDriver, you can remove appium from your package dependency. In practice, appium->appium-windows-driver->WinAppDriver is hard to maintain and introduced a lot of inconsistency. For example, you need to install the exact version of WinAppDriver to make appium happy. After you removed appium from your project:

  • For WinAppDriver, add below dependency and run npx winappdriver to launch WinAppDriver
  • For YWinAppDriver, add below dependency and run npx ywinappdriver to launch YWinAppDriver

3. Get Screenshot and PageSource when test case fails

4. For WinAppDriver, don’t forget ms:experimental-webdriver to make it w3c copmatible

5. Use winappdriver and ywinappdrive service for wdio user.

If your test framework is webdriveio, you can use wdio-winappdriver-service and wdio-ywinappdriver-service to launch and stop winappdriver automatically.

  • Add below dependency based on you are using WinAppDriver or YWinAppDriver
  • Add winappdriver to wdio.conf for WinAppDriver user
  • Add ywinappdriver to wdio.conf for YWinAppDriver user

6. Use appium desktop for XPath

appium desktop: An Inspector that you can use to look at your app’s elements (Safari/Chrome browser, native or hybrid app), get basic information about them, and perform basic interactions with them. This is useful as a way to learn about Appium or as a way to learn about your app so you can write tests for it.

WinAppDriver doesn’t shows all elements in latest appium desktop. You can use YWinAppDriver.

WinAppDriver XPath: /Window/Window/Button[2]

YWinAppDriver XPath: /Body/Window/Window/Button[2]

Most of time, you can remove /Body to convert YWinAppDriver XPath to WinAppDriver XPath.

7. Examples

selenium-webdriver example

webdriverio example

--

--