The PowerToys tests are implemented using Appium and use the [Windows Application Driver](https://github.com/microsoft/WinAppDriver) as an Appium compatible server for Windows applications.
## Prerequisites
- Install the latest stable version of Windows Application Driver in the test machine: [v1.1 Release](https://github.com/microsoft/WinAppDriver/releases/tag/v1.1)
If you have `PowerToys` installed, it can be launched automatically. Otherwise, if you are testing a local build, you should start `PowerToys` before running the tests.
- Start `PowerToys` if necessary (see the Prerequisites).
- Run `WinAppDriver.exe` in Administrator mode, on the test machine. By default it's installed in `C:\Program Files (x86)\Windows Application Driver\`
- **Note:** notifications or other application windows, that are shown above the PowerToys settings window or tray icon, can disrupt the testing process.
When testing on a remote machine, a Firewall exceptions must be added and the IP and port must be passed when starting "Windows Application Driver". Here's how to do it from the [Windows Application Driver FAQ](https://github.com/microsoft/WinAppDriver/wiki/Frequently-Asked-Questions#running-on-a-remote-machine):
Windows Application Driver can run remotely on any Windows 10 machine with `WinAppDriver.exe` installed and running. This *test machine* can then serve any JSON wire protocol commands coming from the *test runner* remotely through the network. Below are the steps to the one-time setup for the *test machine* to receive inbound requests:
1. On the *test machine* you want to run the test application on, open up **Windows Firewall with Advanced Security**
- Select **Inbound Rules** -> **New Rule...**
- **Rule Type** -> **Port**
- Select **TCP**
- Choose specific local port (4723 is WinAppDriver standard)
- **Action** -> **Allow the connection**
- **Profile** -> select all
- **Name** -> optional, choose name for rule (e.g. WinAppDriver remote).
Below command when run in admin command prompt gives same result
- Select `Test > Run > All` tests in the menu bar.
> Once the project is successfully built, you can use the **TestExplorer** to pick and choose the test scenario(s) to run
> If Visual Studio fail to discover and run the test scenarios:
> 1. Select **Tools** > **Options...** > **Test**
> 2. Under *Active Solution*, uncheck *For improved performance, only use test adapters in test assembly folder or as specified in runsettings file*
If a remote test machine is being used, the IP of the test machine must be used to replace the `WindowsApplicationDriverUrl` value in [PowerToysSession.cs](PowerToysSession.cs).
### Extra tools and information
For tests creation you will need a tool that enables you select any UI element and view the element's accessibility data. For this purpose you could use [AccessibilityInsights](https://accessibilityinsights.io/docs/en/windows/overview) or [Inspect](https://docs.microsoft.com/ru-ru/windows/win32/winauto/inspect-objects?redirectedfrom=MSDN).
*`inspect.exe` you can find installed at `C:\Program Files (x86)\Windows Kits\10\bin\<version>\<platform>\inspect.exe`
*`AccessibilityInsights` you can download [here](https://aka.ms/accessibilityinsights-windows/download)
##### How to use Inspect
Open Inspect, find element you need to investigate (by clicking on element or finding it in a tree) and in the right part of inspector window you will see info about this element.
Examples for searching elements with values of `Name`, `AutomationId` and `ControlType`:
```
//use FindElementByAccessibilityId with AutomationId value