Configuration

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.

Screen Resolution

When you run tests on a remote VM most likely screen resolution of unattended RDP session maintained by tscon is 1024x768. This is default screen resolution. And there is no way to change it via RDP connection:

The easiest way to change screen resolution is to use VNC (for example TightVNC). After changing the screen resolution you may uninstall VNC server from the VM. After connecting via VNC open display settings. They will look like this:

Change resolution and save settings.

Now your unattended RDP session will have the resolution you need.