How to Stop Screensaver or Screenlock in UFT or QTP via code?

1
26
Spread the love
  • 1
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
    1
    Share

How to Stop Screensaver or Screenlock
How to Stop Screensaver or Screenlock in UFT or QTP

How to Stop Screensaver or Screenlock in UFT or QTP

This post is useful while we perform automation testing for more than 200 rows of data. As per our office or company policy if a system is untouched for 15 minutes, the screenlock feature gets activated and we need a password to open the screen again. Automation faces regular challenges due to this activity. It is not always okay for UFT to get the screen locked. UFT/QTP may be unresponsive or may halt or stop execution.

Interestingly this screenslock creates issue with other testing tools like Selenium or TOSCA as Well. So even though this post talks about UFT,but we can apply them for Selenium or TOSCA or any other tools as well

Process-1

This sample piece of code gives a mouse move which stops to activate screen saver.. Here we are simulating a mouse click just to tell the Operating system(Windows) that the machine is not free and there is an active user working on it.


Function Handle_SystemLock(Object, Method, Arguments, retVal)
Set o=CreateObject("Mercury.DeviceReplay")
o.mouseMove second(now),100
Set o=Nothing
End Function

Process-2

We can use runtime co-ordinates “x” and “y” with mercury device replay feature,this should help us click on the item.


xcord=Browser("ABC").Page("XYZ").getroproperty("x")
ycord=Browser("ABC").Page("XYZ").getroproperty("Y")
set obj=createobject("Mercury.devicereplay")
obj.mousemove xcord + somevalue , ycord+somevalue
obj.mousedblclick xcord + somevalue , ycord+somevalue,0

Process-3

I have read this book posted here
This is also an interesting solution.


Dim WShShell,Value,Saved
Dim Password
'Password=Inputbox ("Enter Password")
'If Password <> "running" then Wscript.quit
Set WshShell=WScript.CreateObject("WScript.Shell")
On Error Resume Next
Value = WshShell.RegRead("HKCUControl PanelDesktopScreenSaveActive")
Saved = WshShell.RegRead("HKCUControl PanelDesktopSaveScreenSaved")
Err.Clear
'MsgBox Value & "-" & Saved
On Error Goto 0
If Saved <> "1" then
WSHShell.RegWrite "HKCUControl PanelDesktopSaveScreenSave",Value
WSHShell.RegWrite "HKCUControl PanelDesktopSaveScreenSaved","1"
WshShell.RegWrite "HKCUControl PanelDesktopScreenSaveActive","0"
end if
WScript.Quit(0)
and this restores it...
'::Title Restore Saved Screen Saver
'::Version 0 - Date 05 Nov 2000
Option Explicit
Dim WShShell,Value,Saved
Set WshShell=WScript.CreateObject("WScript.Shell")
On Error Resume Next
Value = WshShell.RegRead("HKCUControl PanelDesktopSaveScreenSave")
Saved = WshShell.RegRead("HKCUControl PanelDesktopSaveScreenSaved")
Err.Clear
'MsgBox Value & "-" & Saved
On Error Goto 0
If Saved = "1" then
WSHShell.RegWrite "HKCUControl PanelDesktopScreenSaveActive",Value
WSHShell.RegWrite "HKCUControl PanelDesktopSaveScreenSaved","0"
end if
WScript.Quit(0)

Process-4


Function DisablescreenSaver()
Dim WSHShell, RegKey, ScreenSaver, Result
Set WSHShell = CreateObject("WScript.Shell")
RegKey = "HKCUControl PanelDesktop"
ScreenSaver = WSHShell.RegRead (regkey & "ScreenSaveActive")
If ScreenSaver = 1 Then 'Screen Saver is Enabled
Result = MsgBox("Your screen saver is currently active." & _
vbNewLine & "Would you like to disable it?", 36)
If Result = 6 Then 'clicked yes
WSHShell.RegWrite regkey & "ScreenSaveActive", 0
End If
Else 'Screen Saver is Disabled
Result = MsgBox("Your screen saver is currently disabled." & _
vbNewLine & "Would you like to enable it?", 36)
If Result = 6 Then 'clicked yes
WSHShell.RegWrite regkey & "ScreenSaveActive", 1
End If
End If
End Function

How to Use these codes:

Copy these lines of codes into a notepad and save the notepad as “Test.VBS” to a the test’s main directory. Either you double click on it to activate before the test or using Execute command run this file.
Don't miss out!
Subscribe To Newsletter

Receive top technical news, lesson ideas, travel tips and more!

Invalid email address
Give it a try. You can unsubscribe at any time.

Spread the love
  • 1
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
    1
    Share

1 COMMENT

  1. Nice one…thanks aditi and animesh for your effort….it gave me a chance to go out from my seat while the execution is going on.

    Fantastic approach.

    alen

LEAVE A REPLY

Please enter your comment!
Please enter your name here