Ranorex on a remote desktopThis chapter deals with creating and running Ranorex tests on another computer through a remote desktop connection. It follows a “dos and don’ts” approach.
Structure of this chapter
Do not Automate via Remote Desktop WindowThe first important thing to know is that Ranorex, as every other automation software, is not able to automate via the Remote Desktop window. It is not possible to recognize any controls since the content of the remote desktop is only provided as one big image. The only way to automate using the Remote Desktop window to work coordinate based or with image comparison. This is not recommended by Ranorex because minimal variances in your system will make your tests fail. To guarantee successfully testing on remote machines, you have to install and start all Ranorex Tools you need on the remotely connected machine.
Do not Close or Minimize the RDP WindowRemote Desktop locks the screen when you minimize or close the Remote Desktop window. That causes screenshots to be blank/black and automation to fail. Consequently, if you use Remote Desktop, you need to have the RDP window open during automation and not closed or minimized. Also make sure that the screensaver is not activated on your remotely connected machine as the screensaver will also lock the Remote Desktop’s screen. As a workaround, you can set up one machine having all of your Remote Desktop windows opened. This machine does not do any automation. And while your tests are running on the different Remote Desktops – with the client windows opened on the mentioned machine – you can lock the desktop on this machine. While your client desktop is locked, the Remote Desktop sessions will remain opened and your test will continue. An alternative to RDP is using VNC or the VMWare Remote Console as these tools will not lock the screen when closing or minimizing the remote client window.
Disable Mouse/Keyboard ActivitiesAs an alternative to locking the screen on your Remote Desktop, you can disable the physical mouse and keyboard on the remote machine. To do that just set the Ranorex Keyboard.Enabled and Mouse.Enabled properties to false. Be careful if you disable both keyboard and mouse because both devices will stay disabled until you set the Enabled property back to true or the automation process ends! If you want to disable the input for the whole test cycle, you should set
Keyboard.Enabled = false;
Mouse.Enabled = false;
in the Program.cs file. But again be careful when using these properties because when you set both to false you cannot abort the test without an AbortKey set. So also set
Keyboard.AbortKey = System.Windows.Forms.Keys.Pause;
in Program.cs to abort the test if something unexpected (e.g. an endless loop) happens. You can also use this technique for one recording only. In this case you have to enable/disable the mouse and keyboard controls in user code directly before executing specific actions. As always, don’t forget to enable controls again at the end of your recording and to set an AbortKey.
Use same Color and Resolution SettingsIf you perform image based automation/validation on remote machines, you have to make sure that color and resolution settings are the same as on the machine you made the test/recording on. Please also make sure that you have activated the same windows scheme since your application under test might be displayed differently when having different schemes activated.
Increase Timeouts on Virtual MachinesThings might run a little slower on a virtual machine compared to real machine because multiple virtual machines may share the same physical host. Consequently it can take more time on a Virtual Machine to find some elements. You may need to increase repository timeouts for specific elements or alter your tests to check for ready states on your application under test. It’s recommended to use the global timeout factor to adapt the timeouts for a specific test run.
Keeping remote session unlocked even if closing it
There is a way to keep the remote session unlocked even if you’ve disconnected the RDP session. Find out more here: Ranorex Remote FAQ