Skip to content

Commit

Permalink
Update the steps for running WinAppDriver autonomously
Browse files Browse the repository at this point in the history
The steps in the current documentation leave ambiguity for the reader to figure out setup steps in a CI/CD kind of pipeline.
Adding details around batch files and Task Schedulers to run winappdriver autonomously would help automation/testing teams to setup Winappdriver in a complementary style to the CI/CD flow.
  • Loading branch information
DHowett authored Jul 29, 2022
2 parents a6f3d7b + 6f8d4b0 commit 9c561a5
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion Docs/RunningOnRemoteMachine.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,33 @@ capabilities.setCapability("app", "Microsoft.WindowsCalculator_8wekyb3d8bbwe!App
CalculatorSession = (WindowsDriver)(new WindowsDriver(new URL("http://10.X.X.52:4723/wd/hub"), capabilities));
CalculatorSession.manage().timeouts().implicitlyWait(2, TimeUnit.SECONDS);
CalculatorResult = CalculatorSession.findElementByAccessibilityId("CalculatorResults");
```
```

5. WinAppDriver requires the WinAppDriver server to be listening in order to perform the requisite UI interactions. While Appium generally takes care of this requirement on the local machine, running on a server/remote machine requires a few extra steps as WinAppDriver requires an interactive desktop session. Therefore, we recommend the following (community-contributed) setup steps on the remote machine:
1. Setup a batch file to terminate any old instances of WinAppDriver
- **Name**: `kill_winappdriver.cmd`
- **Contents**: `taskkill /im WinAppDriver.exe /f`
2. Setup a batch file to start WinAppDriver
- **Name** : `LaunchWAD.cmd`
- **Contents** : `cmd start /K "C:/Program Files (x86)/Windows Application Driver/WinAppDriver.exe" 10.x.xx.xx 4723/wd/hub`
- **Note**: The IP address above (10.x.xx.xx) should be replaced with the local network IP address of the server.
3. Setup a batch file to log off the remote session without disconnecting:
- **Name** : `logout-rdp.cmd`
- **Contents**: `for /f "skip=1 tokens=3" %%s in ('query user %USERNAME%') do (%windir%\System32\tscon.exe %%s /dest:console C:\Install\QRes.exe /x 1920 /y 1080)`
- **Notes**
- [Qres](http://qres.sourceforge.net/) is a remote VNC tool that can change the resolution of the target machine to match the local machine
- When using Remote Desktop to connect to a remote computer, closing Remote Desktop locks out the computer and displays the login screen. While the machine is locked, the interactive session is paused. Any currently running or scheduled GUI tests will fail.
- To avoid this, we use the `tscon` utility to disconnect from Remote Desktop. `tscon` returns control to the original local session on the remote computer, bypassing the logon screen. All programs on the remote computer continue running normally, including GUI tests. `logout-rdp.cmd` should be used exclusively to logout from the remote machine, and the admin user should not logout/disconnect manually. You may configure the resolution of the remote machine in the above batch file.
4. Set up two *Scheduled Tasks* on the target machine to terminate WinAppDriver (script from step 5.1) and to start WinAppDriver (script from step 5.2) using the earlier scripts as the target programs.
- Ideally, the Triggers should be *Daily* and *Startup* so that your Continuous Integration build agents will always have an instance of WinAppDriver running.
- These Scheduled Tasks should be set up to run with highest privileges on the machine (as WinAppDriver requires Admin privileges.)
5. Some remote machines or server instances can have a screen lock policy, preventing WinAppDriver from interacting with GUI elements. This can be handled via either updating the policy or by preventing sleep with this small VBScript snippet:

```vbscript
Dim objResult
Set objShell = WScript.CreateObject("WScript.Shell")
Do While True
objResult = objShell.sendkeys("{NUMLOCK}{NUMLOCK}")
Wscript.Sleep (6000)
Loop
```

0 comments on commit 9c561a5

Please sign in to comment.