From 0a3d4a5ee0bbfc2f7bd5c6d3a7f27db0501b2882 Mon Sep 17 00:00:00 2001 From: robin gupta Date: Tue, 17 Nov 2020 13:14:28 +0530 Subject: [PATCH 1/4] Update 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. @timotiusmargo @hassanuz @licanhua @kat-y @DHowett - Kindly review and approve the PR as necessary . --- Docs/RunningOnRemoteMachine.md | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/Docs/RunningOnRemoteMachine.md b/Docs/RunningOnRemoteMachine.md index b547cabd..17f978da 100644 --- a/Docs/RunningOnRemoteMachine.md +++ b/Docs/RunningOnRemoteMachine.md @@ -28,4 +28,22 @@ 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"); - ``` \ No newline at end of file + ``` + 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*: 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) From 819b7416c5e2081bedfce34861316776b8d28d36 Mon Sep 17 00:00:00 2001 From: robin gupta Date: Wed, 18 Nov 2020 14:22:06 +0530 Subject: [PATCH 2/4] Updated readme for steps on lockout/disconnect --- Docs/RunningOnRemoteMachine.md | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/Docs/RunningOnRemoteMachine.md b/Docs/RunningOnRemoteMachine.md index 17f978da..41b32ffd 100644 --- a/Docs/RunningOnRemoteMachine.md +++ b/Docs/RunningOnRemoteMachine.md @@ -33,17 +33,21 @@ CalculatorResult = CalculatorSession.findElementByAccessibilityId("CalculatorRes 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 +- *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 +- *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 -) +- *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*: 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 +Set objShell = WScript.CreateObject("WScript.Shell") +Do While True + objResult = objShell.sendkeys("{NUMLOCK}{NUMLOCK}") + Wscript.Sleep (6000) +Loop` From 0a3a0f5d030a4fd6e32e43ab26f9e989dc07c8c9 Mon Sep 17 00:00:00 2001 From: robin gupta Date: Tue, 28 Jun 2022 11:34:39 +0530 Subject: [PATCH 3/4] Update Docs/RunningOnRemoteMachine.md Added note around QRes Co-authored-by: Canhua Li --- Docs/RunningOnRemoteMachine.md | 1 + 1 file changed, 1 insertion(+) diff --git a/Docs/RunningOnRemoteMachine.md b/Docs/RunningOnRemoteMachine.md index 41b32ffd..620aa5f0 100644 --- a/Docs/RunningOnRemoteMachine.md +++ b/Docs/RunningOnRemoteMachine.md @@ -41,6 +41,7 @@ Therefore we need to follow the below steps on the remote machine for the Window - **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) From 6f8d4b0d4b4f85b007b38444a9c4303c8ed4ee5f Mon Sep 17 00:00:00 2001 From: Dustin Howett Date: Fri, 29 Jul 2022 16:40:14 -0500 Subject: [PATCH 4/4] Reword significantly --- Docs/RunningOnRemoteMachine.md | 44 +++++++++++++++++++--------------- 1 file changed, 25 insertions(+), 19 deletions(-) diff --git a/Docs/RunningOnRemoteMachine.md b/Docs/RunningOnRemoteMachine.md index 620aa5f0..4b6a3fca 100644 --- a/Docs/RunningOnRemoteMachine.md +++ b/Docs/RunningOnRemoteMachine.md @@ -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 +```