Skip to main content

Image Matching on an Inactive Remote Desktop

One of the advantages of running Cycle scripts on a dedicated box is the ability to execute the tests without inhibiting your ability to work locally. This document describes how to allow Cycle to successfully image match on a remote desktop while not being actively connected to the box. This is especially useful if scheduling a suite of regression tests that utilize image matching.

Approach

In order for image matching to work even if you disconnect your remote desktop connection, you must keep your desktop active. The way to do this is by pointing your session to the console session. The console session is what you would see if you had a monitor hooked up to the server. When you connect to a machine via remote desktop from Windows server 2008 and beyond, you establish your session. By pointing your session to the console session, Cycle will still have a desktop to look at, as opposed to a black screen.

Two ways you can point your session to the console session are:

  1. Manually via a Cycle Scenario
  2. Triggering Task Scheduler on User Disconnect

Manual Method

The manual solution requires adding a scenario to the beginning of your regression test. When executed, the tscon command will point your session to the console session and kick you off. If you were to run this and immediately reconnect, you’d notice that the screen is not black when attempting to image match.

  1. In order to create this scenario you will need the session id from your Remote Desktop session. To find this, with your remote desktop connected, open the command prompt and run the command query session:

    Query Session

    This will return the Session Names and IDs of all open sessions. The one you will need is for your rdp-... session, (example underlined above).

  2. With this you can use the following scenario:

    Scenario: Switch session to console Given I right click "Image:images\commandprompt.png" And I click "Image:images\RunAsAdmin.png" Then I wait 2 seconds And I enter "tscon 2 /dest:console" And I press keys Enter And I wait 5 seconds Then I enter "query session" And I press keys Enter And I wait 2 seconds Then I fail step And I press keys WIN+DOWN

Note: You will need to update the Step Then I enter "tscon 2 /dest:console" to replace the number 2 with the session id from the previous step.

One of the caveats of this method is you will need this scenario to run at the beginning of your testing if you would like to disconnect your remote session and keep image matching active. This means that you won’t be able to actively view the regression tests and disconnect from remote desktop as you please.

Task Scheduler Method

In order to be able to disconnect from remote desktop as you please and allow image matching to work successfully, you must schedule a task to execute a batch file that runs the same logic as the manual scenario.

  1. Launch task scheduler.

  2. Under task scheduler, select Create Task. Enter a Name, Description, and select Run with highest privileges.

    Task Scheduler

  3. Create a trigger to begin the task On disconnect from a user session...Specific user. If you do not select this, you will get locked out of the server (upon reconnecting, this will execute and kick you back off).

    Task Scheduler Trigger

  4. Create an action to call a batch file.

    Task Scheduler Action

  5. The batch file is listed below. It runs the same logic manually run via command prompt. Replace tryon1 with your user. You’ll find the log file in C:\Users<user_id>\AppData\Local\Temp.

    Image Match Batch File

Additional Note

In order for Cycle image matching to work properly on the console session, the resolution on the console session must equal the resolution used to capture the images. You can get and set the console resolution via Get-DisplayResolution and Set-DisplayResolution <width> <height>. You must log out for this to take effect.