Friday, October 12, 2018

GUI tests on Windows RDP session stops working after minimizing or disconnecting

Many automation tests require the GUI based application or scripts to keep running on a windows session.
In a standard IT industry scenario, we use RDP session (with mstsc) to connect to a windows server.

However, the challenge comes when we need to leave these applications unattended. In most scenarios, once you minimize the RDP session window, all the GUI operation get stuck, and the application or script is unable to proceed normally.

The situation worsens when we have even longer running tests/scripts, as its not possible for end user to continuously monitor the RDP session.

The trick to deal with both these situations are mentioned below:

1. Minimizing the RDP window halts the GUI test/scripts:

To prevent the minimized RDP sessino from stopping your work, make the following changes

a. Launch registry editor using regedit
b. Navigate to the below two following registries & create an entry as shown below:

HKEY_CURRENT_USER\Software\Microsoft\Terminal Server Client
HKEY_LOCAL_MACHINE\Software\Microsoft\Terminal Server Client

Create an entry of type DWORD, with name RemoteDesktop_SuppressWhenMinimized and set its value to 2(decimal value).

2. Disconnecting the RDP session totally stop the execution of GUI activities:

Sometimes is impractical to keep the session continuously monitored. In my case, I had setup a script that needs to runs every 10 minutes, 24x7, and it didn't need any user inputs.

To achieve successful execution of GUI based tests or scripts, with "unconnected*" [*notice that I avoided the term disconnected], use the below commands for closing the RDP session

a. Create a bat file with below contents:

for /f "skip=1 tokens=3" %%s in ('query user %USERNAME%') do ( %windir%\System32\tscon.exe %%s /dest:console )

a. Run the above created file with admin privilege:
- Please note, the script won't work unless you run it as administrator.

With this, your session will show disconnected, however, the user will in reality will be still logged in, and GUI tasks will go on as expected.

Thanks to some of the blogs on web:

No comments:

Post a Comment