How to check if Screensaver is active?

Experiences, small talk, and other automation gossip.
Posts: 116
Joined: Tue Jun 03, 2014 10:15 am
Location: Hamburg, Germany

How to check if Screensaver is active?

Post by BCTest » Mon Feb 08, 2016 10:05 am

For one of our tests it is necessary to avoid the date change, so we implemented a pause in the test. Sometime the pause is so long that the screensaver activates.
Of course we can turn the screensaver off but only for my interest: How can Ranorex check if the screensaver is active? And what would be the preferred method to turn off the screensaver? Mouse move?


Posts: 107
Joined: Fri Jul 03, 2015 9:18 am

Re: How to check if Screensaver is active?

Post by jma » Wed Feb 10, 2016 5:35 pm

Hi Thomas,

Implementing such behavior would probably be possible using the .NET Framework.
I would suggest having a look at the following Microsoft web page: Screen Saver notifications

Nevertheless, I would suggest turning off the screensaver during test execution, which is very prone to failure.

Posts: 2683
Joined: Tue Feb 07, 2012 4:14 pm
Location: Austin, Texas, USA

Re: How to check if Screensaver is active?

Post by krstcs » Wed Feb 10, 2016 6:03 pm

I agree with jma. Screensavers and screen-locking should be disabled during testing, if possible.

If you can't disable them due to group policy (like me... :( ), you can use the following work-around.

Instead of just waiting for a certain amount of time, you could wait for a much shorter period, but loop over it so that the total adds up to what you want. In the loop, you wait for the small amount time needed, then move the mouse a little bit (just enough to keep the screen active/unlocked) and the loop again:

Code: Select all

int numberOfLoops = 20;
int secondsPerLoop = 30;

for (int i = 0; i < numberOfLoops; i++) {
  Delay.Milliseconds(secondsPerLoop * 1000);

  Mouse.MoveTo(repo.MySystem.Self, Location.Center);
  Mouse.MoveTo(Mouse.Position.X + 5, Mouse.Position.Y + 5);  //move it just enough...
This is what I do to make sure that both my OS and my AUT don't lock on me. I use it when I'm attempting to get a SQL Server APP_LOCK due to the need to keep multiple instances of my AUT from using the same customer at the same time.

NOTE: You could do a while-loop instead if you need to wait for a certain time, etc. Just wanted to show a possible solution... :D
Shortcuts usually aren't...