Running UI automation with RDP session disconnected

Root Cause of failure:
When you close a Remote Desktop session on a remote computer, it locks out the computer, displaying the logon screen. In the locked mode, the user session on the computer does not have GUI, and any GUI tests on that computer fails.


Resolution:

  1. On the remote computer, create a batch file with this code for /f "skip=1 tokens=3" %%s in ('query user %USERNAME%') do ( %windir%\System32\tscon.exe %%s /dest:console)
  2. Create a desktop shortcut to this file. To do this, right-click the batch file and select Send to | Desktop (create shortcut).
  3. When you need to disconnect from Remote Desktop, run the batch file with admin rights.

 

Alternate Resolution:

  1. There needs to be done some registry changes: 
  2. Launch the Registry editor (regedit.exe)
  3. Navigate to one of the following Registry keys, depending on whether you wish to modify the Remote Desktop settings only for the current user or for all users on the computer:
  4. HKEY_CURRENT_USER\Software\Microsoft\Terminal Server Client
  5. HKEY_LOCAL_MACHINE\Software\Microsoft\Terminal Server Client
  6. Create a DWORD value named RemoteDesktop_SuppressWhenMinimized and set it to 2 (hexadecimal or decimal)
  7. Through task manager rdpclip.exe has to be stopped. 
  8. Disconnect the RDP session by running the following command: tscon %sessionname% /dest:console

 

Troubleshooting scenarios and solution:

  1. Post disconnecting from RDP session using TSCON utility image-based automation or mouse click operation is failing

RCA: When user disconnects from RDP session screen resolution of unattended RDP session maintained by TSCON is 1024x768 or 640 * 480. If UI automation is screen resolution dependent or application gets distorted in mentioned screen resolution, then UI automation may fail.

Resolution: Post disconnecting from RDP use VNC tool to connect to machine and change resolution. Post changing resolution, you can disconnect from VNC session

Post disconnecting from RDP session using TSCON utility after some time Key Events, Print Screen and Mouse Click operation is failing

  1. RCA: Some time due to machine level setting system goes in sleep mode which may lead to failure of interactions such as Key Events, Print Screen and Mouse Click operation. Configured time can be seen in Control Panel > Power Option > Edit Plan setting for selected plan.

Resolution: Try changing the power plan setting. If the same do not work then use a third-party tool ( For example: caffeine.exe) or write a power shell program which sends a non-intrusive key event at regular interval on machine where automation is running.

  1. The Robot machine becomes unresponsive and shows high CPU usage at some point after starting the process execution. It occurs on Windows 10 v1903 machines.

RCA: This is a Microsoft known issue on Windows 10 v1903 which affects the runtime of the DWM.exe file, leading to high CPU usage upon completion of a Remote Desktop session.

Resolution: It is highly recommended to apply the KB4522355 update on the faulty Windows machine to fix this issue.