Google Search Results
You arrived here after searching for the following phrases:
Click a phrase to jump to the first occurrence, or return to the search results.
|
Somehow HP help files do not provide information about this powerful feature. You can find DeviceReplay property under Java add-in, but for those who doesn’t use Java add-in might think that the feature is not available for them. |
Why Device Replay?
|
Sometimes we need to do specific action on the UI, for example a right click on an object, use Fx keys to activate some hotkey, or just when object.Set and object.Type methods, somehow doesn’t work for you. Also it can be useful to type symbols and letters from different languages, without installing special fonts or changing the keyboard layout, and this can be very usefull for testing multi-language applications. For mouse operation i found very useful the DragDrop method, to drag and drop items from one frame to another or between applications. |
|
The deviceReplay object is used to simulate mouse clicks and movements and also keyboard input. To use DeviceReplay you must ensure that your AUT is the active window. If you want to perform an action on a object, the object must have the focus. For Windows applications you can use the Activate method |
|
Window( "W" ).Activate micLeftBtn |
|
To set the focus on a specific object in windows, usually the Click method will do the job. For web environment applications the Activate method is not supported, so yo can use the following trick : |
|
hwnd = Browser( "B" ).GetROProperty( "hwnd" ) Window( "hwnd:=" & hwnd ).Activate micLeftBtn |
|
To set the focus on any object usually the FireEvent “onfocusin” or object.focus e.g. WebEdit( "WE" ).object.focus or WebEdit( "WE" ).FireEvent "onfocusin" For accessing the device replay methods you need first to create the devicereplay object |
|
Set deviceReplay = CreateObject( "Mercury.DeviceReplay" ) |
System.Windows.Forms.Control Class
|
Another useful feature is to retrieve the current mouse ( cursor ) position in the screen according to the limitation of the DeviceReplay object. The System.Windows.Forms.Control base Class Defines the base class for controls, which are components with visual representation. the MousePosition property Gets the position of the mouse cursor in screen coordinates. The MousePosition property returns a Point that represents the mouse cursor position at the time the property was referenced. |
Where is my mouse?
|
Set ctlr = DotNetFactory.CreateInstance("System.Windows.Forms.Control") For i = 1 To 10 Wait 2 Print "1. X=" & ctlr.MousePosition.X & "; Y=" & ctlr.MousePosition.Y Next |
Mercury.DeviceReplay Methods
SendString Method
|
|
Sends one or more keystrokes to the active window, as if typed on the keyboard. |
|
|
|
object.SendString( str ) |
|
|
|
Parameter |
Description |
|
|
object |
Always a Mercury.DeviceReplay object |
|
|
str |
the String to be typed |
|
|
None |
|
|
|
The Following example will activate notepad and type a string. |
|
|
|
Set deviceReplay = CreateObject( "Mercury.DeviceReplay" ) SystemUtil.Run "notepad.exe", "", "", "open" ' ** this line always identifies the notepad window. Window( "nativeclass:=Notepad", "index:=0″ ).Activate micLeftBtn deviceReplay.SendString( "DeviceReplay" ) Set deviceReplay = Nothing |
|
KeyDown Method
|
|
Simulates a key press and hold via keyboard ( KEY_DOWN event in Win32 ) |
||
|
|
object.KeyDown( key ) |
||
|
|
Parameter |
Description |
|
|
|
object |
Always a Mercury.DeviceReplay object |
|
|
|
key |
the key numeric code for more information on key codes see Key Codes Reference |
|
|
|
None |
||
|
|
The Following example will activate notepad and type a string in uppercase and lowercase in a new line. Note that the shift key remains pressed while sending the first string. |
||
|
|
Const VK_SHIFT = 42 Const VK_RETURN = 28 Set deviceReplay = CreateObject( "Mercury.DeviceReplay" ) SystemUtil.Run "notepad.exe", "", "", "open" Window( "nativeclass:=Notepad", "index:=0″ ).Activate micLeftBtn ' ** Typing uppercase deviceReplay.KeyDown VK_SHIFT deviceReplay.SendString( "devicereplay" ) deviceReplay.PressKey VK_RETURN deviceReplay.KeyUp VK_SHIFT ' ** Typing in lower case deviceReplay.SendString( "devicereplay" ) Set deviceReplay = Nothing |
||
|
|
|
||
|
|
Simulates a key released via keyboard. |
||
|
|
object.KeyUp( key ) |
||
|
|
Parameter |
Description |
|
|
|
object |
Always a Mercury.DeviceReplay object |
|
|
|
key |
the key numeric code for more information on key codes see Key Codes Reference |
|
|
|
None |
||
|
|
The Following example will activate the open menu of notepad using the hotkey Ctrl+O and will close it using Escape. |
||
|
|
Const VK_O = 24 Const VK_CONTROL = 29 Const VK_ESCAPE = 1 Set deviceReplay = CreateObject( "Mercury.DeviceReplay" ) SystemUtil.Run "notepad.exe", "", "", "open" Window( "nativeclass:=Notepad", "index:=0″ ).Activate micLeftBtn ' ** Typing uppercase Wait 1 ' ** Opening the menu Ctrl + O deviceReplay.KeyDown VK_CONTROL deviceReplay.PressKey VK_O deviceReplay.KeyUp VK_CONTROL Wait 2 ' ** Closing the menu deviceReplay.PressKey VK_ESCAPE deviceReplay.SendString "Menu Open, was closed." Set deviceReplay = Nothing |
||
|
|
|
||
PressKey Method
|
|
Simulates a key pressed and immediately released via keyboard. |
|
|
|
object.PressKey( key ) |
|
|
|
Parameter |
Description |
|
|
object |
Always a Mercury.DeviceReplay object |
|
|
key |
the key numeric code for more information on key codes see Key Codes Reference |
|
|
None |
|
|
|
The Following example will activate the open menu of notepad using the hotkey Ctrl+O and will close it using Escape. |
|
|
|
Const VK_O = 24 : Const VK_F = 33 Const VK_CONTROL = 29 : Const VK_ESCAPE = 1 : Const VK_MENU = 56 Set deviceReplay = CreateObject( "Mercury.DeviceReplay" ) SystemUtil.Run "notepad.exe", "", "", "open" Window( "nativeclass:=Notepad", "index:=0″ ).Activate micLeftBtn Wait 1 ' ** Opening the menu Alt + F + O deviceReplay.PressKey VK_MENU deviceReplay.PressKey VK_F deviceReplay.PressKey VK_O Wait 2 ' ** Closing the menu deviceReplay.PressKey VK_ESCAPE deviceReplay.SendString "Open menu was closed." Set deviceReplay = Nothing |
|
PressNKeys Method
|
|
Simulates a key pressed and immediately released several times via keyboard. |
|
|
|
object.PressNKey( key, N ) |
|
|
|
Parameter |
Description |
|
|
object |
Always a Mercury.DeviceReplay object |
|
|
||


Yaron Assa
