Skip to content

Commit 9c561a5

Browse files
authored
Update the steps for running WinAppDriver autonomously
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.
2 parents a6f3d7b + 6f8d4b0 commit 9c561a5

File tree

1 file changed

+30
-1
lines changed

1 file changed

+30
-1
lines changed

Docs/RunningOnRemoteMachine.md

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,33 @@ capabilities.setCapability("app", "Microsoft.WindowsCalculator_8wekyb3d8bbwe!App
2828
CalculatorSession = (WindowsDriver)(new WindowsDriver(new URL("http://10.X.X.52:4723/wd/hub"), capabilities));
2929
CalculatorSession.manage().timeouts().implicitlyWait(2, TimeUnit.SECONDS);
3030
CalculatorResult = CalculatorSession.findElementByAccessibilityId("CalculatorResults");
31-
```
31+
```
32+
33+
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:
34+
1. Setup a batch file to terminate any old instances of WinAppDriver
35+
- **Name**: `kill_winappdriver.cmd`
36+
- **Contents**: `taskkill /im WinAppDriver.exe /f`
37+
2. Setup a batch file to start WinAppDriver
38+
- **Name** : `LaunchWAD.cmd`
39+
- **Contents** : `cmd start /K "C:/Program Files (x86)/Windows Application Driver/WinAppDriver.exe" 10.x.xx.xx 4723/wd/hub`
40+
- **Note**: The IP address above (10.x.xx.xx) should be replaced with the local network IP address of the server.
41+
3. Setup a batch file to log off the remote session without disconnecting:
42+
- **Name** : `logout-rdp.cmd`
43+
- **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)`
44+
- **Notes**
45+
- [Qres](http://qres.sourceforge.net/) is a remote VNC tool that can change the resolution of the target machine to match the local machine
46+
- 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.
47+
- 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.
48+
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.
49+
- Ideally, the Triggers should be *Daily* and *Startup* so that your Continuous Integration build agents will always have an instance of WinAppDriver running.
50+
- These Scheduled Tasks should be set up to run with highest privileges on the machine (as WinAppDriver requires Admin privileges.)
51+
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:
52+
53+
```vbscript
54+
Dim objResult
55+
Set objShell = WScript.CreateObject("WScript.Shell")
56+
Do While True
57+
objResult = objShell.sendkeys("{NUMLOCK}{NUMLOCK}")
58+
Wscript.Sleep (6000)
59+
Loop
60+
```

0 commit comments

Comments
 (0)