Skip to content

Commit

Permalink
Reword significantly
Browse files Browse the repository at this point in the history
  • Loading branch information
DHowett committed Jul 29, 2022
1 parent 0a3a0f5 commit 6f8d4b0
Showing 1 changed file with 25 additions and 19 deletions.
44 changes: 25 additions & 19 deletions Docs/RunningOnRemoteMachine.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,26 +29,32 @@ CalculatorSession = (WindowsDriver)(new WindowsDriver(new URL("http://10.X.X.52:
CalculatorSession.manage().timeouts().implicitlyWait(2, TimeUnit.SECONDS);
CalculatorResult = CalculatorSession.findElementByAccessibilityId("CalculatorResults");
```
5.WinAppDriver requires the Winappdriver server to be listening on the local host or IP address in order to perform the requisite UI interactions. While Appium generally takes care of this requirement on the local , for running on a server/remote machine, we need to perform a few extra steps as Winappdriver requires a GUI Output and the Winappdriver server running in an interactive shell.
Therefore we need to follow the below steps on the remote machine for the Windows GUI tests to run in an autonomous fashion :
- **5.1**. Setup Batch file to kill any old instances of WinAppDriver - This will be used in the KILLWAD scheduled task later
- *Name* : kill_winappdriver.bat
- *Contents* : `taskkill /im WinAppDriver.exe /f`
- **5.2**. Setup Batch file to start WinAppdriver - This will be used in the StartWAD scheduled task later
- *Name* : LaunchWAD.bat
- *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 IP address of the server/remote machine
- **5.3**. Setup Batch file to logout (without disconnecting) from the remote machine :
- *Name* : logout-rdp.bat
- *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)`
- *Note*: Qres (http://qres.sourceforge.net/) is a remote vnc tool to change the resolution of the target machine to match the local machine
- *Note*: When using Remote Desktop to connect to a remote computer, closing Remote Desktop locks out the computer and displays the login screen. In the locked mode, the computer does not have GUI, so any currently running or scheduled GUI tests will fail.
To avoid problems with GUI tests, we use the tscon utility to disconnect from Remote Desktop. tscon returns the 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. Therefore logout-rdp.bat should be exclusively used to logout from the remote machine and the admin user should not logout/disconnect manually from the remote . Also, the resolution is passed as a parameter in the above batch file as 1920x1080
- **5.4** . Setup *Scheduled Tasks* on the target machine to kill Winappdriver (as per the BAT file in 5.1) and to start Winappdriver (as per the BAT file in 5.2) as the target programs. Ideally the Triggers should be *Daily* and *Startup* , so that the scripts running via the Test runner (Ex: JENKINS) , always have an instance of Winappdriver running on the server. These Scheduled Tasks should be setup to run with highest privileges on the machine (as Winappdriver requires to be run with Admin rights)
- **5.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 running a small script as follows :
`Dim objResult
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`
Loop
```

0 comments on commit 6f8d4b0

Please sign in to comment.