It is common to use UI tests with RDP connected to remote VM. By default this works only while RDP window is open and client is connected. On disconnect remote session gets locked and UI becomes unavaliable for the test. This topic covers a workaround.
You need to have RDP client running for UI tests to execute successfully. RDP client may be minimized with use of the following KB topic.
It requires another host to keep this RDP connection and stay active itself. Microsoft provides special tool tscon for it.
Here is a way on how to use it:
1. Connect via RDP to your VM where you running tests.
2. Inside an RDP session create a batch file (I.e. disconn.bat) with the following contents:
for /f "skip=1 tokens=3" %%s in ('query user %USERNAME%') do (
%windir%\System32\tscon.exe %%s /dest:console
3. Create a desktop shortcut for this batch file.
4. In the shortcut advanced properties and enable 'Run as Administrator'.
How to use:
1. Double click on the shortcut to finish an RDP session.
2. Expected behavior: your RDP client should immediately disconnect.
3. Your scheduled UI tests should now work properly. Please, note that you should always use the shortcut to disconnect to keep your remote host in UI Automation-friendly mode.