Page 1 of 1

How to check if Screensaver is active?

Posted: Mon Feb 08, 2016 10:05 am
by BCTest
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?

Regards,
Thomas.

Re: How to check if Screensaver is active?

Posted: Wed Feb 10, 2016 5:35 pm
by jma
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.

Re: How to check if Screensaver is active?

Posted: Wed Feb 10, 2016 6:03 pm
by krstcs
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