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.
|
(This is the Russian version of the article. The English version is Here). По непонятным причинам HP не публекует информацию о DeviceReplay. Вы можете познакомитъся сo свойствами DeviceReplay работая с Java Аппликацией и используя Java add-in , а тот кто не сталкивался с Java скорее всего не предпологает о существовании таких возможностей . |
Почему DeviceReplay?
|
Иногда требуется воссоздать определенное действие , к примеру кликнуть на определенный объект на нашем Юзер Интерфейс правым кликом или когда применить Type / Set методы невозможно, а план тестирования этого требует. Так же если требуется послать определенный стринг содержащий не языковые символы , а в автоматическом тестировании это случается не редко , лучшии способ - это DeviceReplay. |
|
Применяется для симуляции движений и кликов мышки а также вывода данных с клавиатуры на экран .Для успешного использования Device Replay нужно удостовериться , что аппликация поднята и нужное окно активировано . Для виндоусовских аппликаций можно использовать Activate метод : |
|
Window( "W" ).Activate micLeftBtn |
|
Для фокусировки на определенном объекте внутри окна лучший способ это просто кликнуть на этот объект. Веб среда не поддерживает напрямую “Activate метод” , поэтому рекомендуется активировать аппликацию следующим способом : |
|
hwnd = Browser( "B" ).GetROProperty( "hwnd" ) Window( "hwnd:=" & hwnd ).Activate micLeftBtn |
|
Для фокусировки на определенном объекте внутри Веб окна обычно используется : WebEdit( "WE" ).object.focus or WebEdit( "WE" ).FireEvent "onfocusin" |
|
Как начать работать с DeviceReplay ? Для начала использования device replay метода нужно создать объект : |
|
Set deviceReplay = CreateObject( "Mercury.DeviceReplay" ) |
Microsoft.VisualBasic.Devices.Keyboard
System.Windows.Forms.Control Class
|
Другое замечательное свойство очень необходимое иногда в работе с QTP это возможность определить положение курсора на экране . System.Windows.Forms.Control это основой класс, с помощью которого можно контролировать любое движение курсора на экране. MousePosition свойство возвращающее позицию курсора по временным интервалом : |
Где была моя мышка?
|
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
|
|
С помощью Mercury.Device удобно производить вывод данных с клавиатуры на экран.. |
|
|
|
object.SendString( str ) |
|
|
|
Parameter |
Description |
|
|
object |
Always a Mercury.DeviceReplay object |
|
|
str |
the String to be typed |
|
|
None |
|
|
|
Данный пример запустит аппликацию notepad и запишет текст DeviceReplay |
|
|
|
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
|
|
||||||
|
|
Симулирование нажтой клавиши ( 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 |
|
||||
|
|
||||||
|
|
Данный пример запустит аппликацию notepad и запишет текст в двух строчках – заглавными и маленькими буквами , в добавок shift key будет нажата во время посылки стринга. |
|
||||
|
|
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 |
|
||||
|
|
||||||
|
|
|
|
||||
|
|
|
|
|
|||
|
|
Строка содержавшая KeyUp Method. равносильна постоянно "нажатой" клавише . |
||
|
|
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 |
||
|
|
Данный пример активизирует notepad и использует hotkey Ctrl+O и закроет notepad с помошью 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
|
|
Так же возможно создавать различные комбинации нажатия клавиш. |
|
|
|
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 |
|
|
|
Пример нажатия и немедленного освобождения клавиши: |
|
|
|
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
|
|
object.PressNKey( key, N ), N - время нажатия клавиши. |
|
|
|
object.PressNKey( key, N ) |
|
|
|
Parameter |
Description |
|
|
object |
Always a Mercury.DeviceReplay object |
|
|
key |
the key numeric code for more information on key codes see Key Codes Reference |
|
|
N |
The number of repetitions. |
|
|
None |
|
|
|
|
|
Examples
Example 1 - States of
|
Option Explicit
Const VK_RETURN = 28 : Const VK_F = 33 : Const VK_O = 24 Const VK_TAB = 15 : Const VK_F5 = 63 Const VK_CAPITAL = 58 : Const VK_NUMLOCK = 69 Const VK_SUBTRACT = 74 : Const VK_MULTIPLY = 55 Const VK_MENU = 56
Dim deviceReplay
Private Sub SetupKeyboard() Const CLASS_NAME = "Microsoft.VisualBasic.Devices.Keyboard" Const ASSEMBLY = "Microsoft.VisualBasic" Dim Keyboard
Set Keyboard = DotNetFactory.CreateInstance( CLASS_NAME, ASSEMBLY ) If CBool( Keyboard.CapsLock ) Then deviceReplay.PressKey VK_CAPITAL End If If CBool( Keyboard.NumLock ) = False Then deviceReplay.PressKey VK_NUMLOCK End If Set Keyboard = Nothing End Sub
Private Sub SetupNotepad() deviceReplay.PressKey VK_MENU deviceReplay.PressKey VK_O deviceReplay.PressKey VK_F deviceReplay.SendString "Courier New" deviceReplay.PressKey VK_TAB deviceReplay.PressKey VK_TAB deviceReplay.SendString "14″ deviceReplay.PressKey VK_RETURN Wait 1 End Sub
Private Sub PrintRow( ByVal state, ByVal usps, byVal capital ) deviceReplay.SendString state deviceReplay.PressKey VK_TAB If Len( state ) < 8 Then deviceReplay.PressKey VK_TAB End If deviceReplay.SendString usps deviceReplay.PressKey VK_TAB deviceReplay.SendString capital deviceReplay.PressKey VK_RETURN End Sub
Set deviceReplay = CreateObject( "Mercury.DeviceReplay" ) SystemUtil.Run "notepad.exe", "", "", "open", 3 Window( "nativeclass:=Notepad", "index:=0″ ).Activate micLeftBtn ' ** Setup Notepad - Font courier new, size 14, ' ** NUM-LOCK pressed and CAPS-LOCK unpressed Call SetupKeyboard() Call SetupNotepad() ' ** inserting date deviceReplay.PressKey VK_F5 deviceReplay.PressKey VK_RETURN ' ** Inserting Title deviceReplay.PressNKeys VK_TAB, 3 deviceReplay.SendString " deviceReplay.PressKey VK_RETURN deviceReplay.PressNKeys VK_TAB, 3 deviceReplay.PressNKeys VK_MULTIPLY, Len( " deviceReplay.PressNKeys VK_RETURN, 2 ' ** Table Headers deviceReplay.SendString "State" deviceReplay.PressKey VK_TAB deviceReplay.PressKey VK_TAB deviceReplay.SendString "USPS" deviceReplay.PressKey VK_TAB deviceReplay.SendString "Capital" deviceReplay.PressKey VK_RETURN deviceReplay.PressNKeys VK_SUBTRACT, 31 deviceReplay.PressKey VK_RETURN ' ** Print Data Call PrintRow( " Call PrintRow( " Call PrintRow( " Call PrintRow( " Call PrintRow( " Call PrintRow( " Call PrintRow( " Call PrintRow( " Call PrintRow( " Call PrintRow( "Georgia", "GA", " Call PrintRow( " Call PrintRow( " Call PrintRow( " Call PrintRow( "Indiana", "IN", " Call PrintRow( " Call PrintRow( " Call PrintRow( " Call PrintRow( " Call PrintRow( " Call PrintRow( " Call PrintRow( " Call PrintRow( " Call PrintRow( " Call PrintRow( " Call PrintRow( " Call PrintRow( " Call PrintRow( " Call PrintRow( " Call PrintRow( " Call PrintRow( " Call PrintRow( " Call PrintRow( " Call PrintRow( " Call PrintRow( " Call PrintRow( " Call PrintRow( " Call PrintRow( " Call PrintRow( " Call PrintRow( " Call PrintRow( " Call PrintRow( " Call PrintRow( " Call PrintRow( " Call PrintRow( " Call PrintRow( " Call PrintRow( "Virginia", "VA", " Call PrintRow( "Washington", "WA", " Call PrintRow( " Call PrintRow( " Call PrintRow( "
Set deviceReplay = Nothing |
Example 2 - Latin characters and Symbols
|
Option Explicit
Const VK_NUMPAD0 = 82 Const VK_NUMPAD1 = 79 Const VK_NUMPAD2 = 80 Const VK_NUMPAD3 = 81 Const VK_NUMPAD4 = 75 Const VK_NUMPAD5 = 76 Const VK_NUMPAD6 = 77 Const VK_NUMPAD7 = 71 Const VK_NUMPAD8 = 72 Const VK_NUMPAD9 = 73 Const VK_MENU = 56 Const VK_SHIFT = 42 Const VK_RETURN = 28 Const VK_F = 33 Const VK_O = 24 Const VK_TAB = 15 Const VK_F5 = 63 Const VK_NUMLOCK = 69 Dim deviceReplay
Private Sub SetupKeyboard() Const CLASS_NAME = "Microsoft.VisualBasic.Devices.Keyboard" Const ASSEMBLY = "Microsoft.VisualBasic" Dim Keyboard
Set Keyboard = DotNetFactory.CreateInstance( CLASS_NAME, ASSEMBLY ) If CBool( Keyboard.CapsLock ) Then deviceReplay.PressKey VK_CAPITAL End If If CBool( Keyboard.NumLock ) = False Then deviceReplay.PressKey VK_NUMLOCK End If Set Keyboard = Nothing End Sub
Private Sub SetupNotepad() deviceReplay.PressKey VK_MENU deviceReplay.PressKey VK_O deviceReplay.PressKey VK_F deviceReplay.SendString "Courier New" deviceReplay.PressKey VK_TAB deviceReplay.PressKey VK_TAB deviceReplay.SendString "14″ deviceReplay.PressKey VK_RETURN Wait 1 End Sub
Private Sub PrintCharacter( ByVal code ) Dim i, digit
deviceReplay.KeyDown VK_MENU For i = 1 To Len( code ) digit = Mid( code, i, 1 ) Execute "deviceReplay.PressKey VK_NUMPAD" & digit Next deviceReplay.KeyUp VK_MENU deviceReplay.PressKey VK_RETURN End Sub
Set deviceReplay = CreateObject( "Mercury.DeviceReplay" ) SystemUtil.Run "notepad.exe", "", "", "open", 3 Window( "nativeclass:=Notepad", "index:=0″ ).Activate micLeftBtn ' ** Setup Notepad - Font courier new, size 14, ' ** NUM-LOCK pressed and CAPS-LOCK unpressed Call SetupKeyboard() Call SetupNotepad() ' ** inserting date deviceReplay.PressKey VK_F5 deviceReplay.PressKey VK_RETURN ' ** a grave character deviceReplay.SendString "A grave: " Call PrintCharacter( "0192″ ) ' ** O circumflex character deviceReplay.SendString "O circumflex: " Call PrintCharacter( "0212″ ) ' ** s caron character deviceReplay.SendString "s caron: " Call PrintCharacter( "0154″ ) ' ** n tilde character deviceReplay.SendString "n tilde: " Call PrintCharacter( "164″ ) ' ** Y umlaut character deviceReplay.SendString "Y umlaut: " Call PrintCharacter( "0159″ ) ' ** c cedila character deviceReplay.SendString "c cedila: " Call PrintCharacter( "0231″ ) ' ** O with accent character deviceReplay.SendString "O with accent: " Call PrintCharacter( "0211″ ) ' ** Inverted question mark character deviceReplay.SendString "Inverted question mark: " Call PrintCharacter( "168″ ) ' ** Euro character deviceReplay.SendString "Euro: " Call PrintCharacter( "0128″ ) ' ** i with accent character deviceReplay.SendString "i with accent : " Call PrintCharacter( "0237″ ) ' ** Male Sign character deviceReplay.SendString "Male Sign: " Call PrintCharacter( "11″ ) ' ** AE ligature character deviceReplay.SendString "AE ligature: " Call PrintCharacter( "0198″ ) ' ** aa character deviceReplay.SendString "aa: " Call PrintCharacter( "0197″ ) ' ** oethel character deviceReplay.SendString "oethel: " Call PrintCharacter( "0156″ ) ' ** Eth character deviceReplay.SendString "Eth: " Call PrintCharacter( "0208″ ) ' ** Uppercase Sigma character deviceReplay.SendString "Uppercase Sigma: " Call PrintCharacter( "228″ )
Set deviceReplay = Nothing |
DragAndDrop Method
MouseClick Method
|
Можно так же комбинировать MouseDown, MouseMove and MouseUp методы |
|
|
object.MouseClick( x, y, Button ) |
|
|
Parameter |
Description |
|
object |
Always a Mercury.DeviceReplay object |
|
x |
the x absolute coordinate in a screen for perform the click |
|
y |
the y absolute coordinate in a screen for perform the click |
|
button |
possible values LEFT_MOUSE_BUTTON = 0 MIDDLE_MOUSE_BUTTON = 1 RIGHT_MOUSE_BUTTON = 2 |
|
None |
|
|
Данный пример требует небольшой подготовки и навыков работы с Quick Test Professional . Цель примера выполнить метод DragAndDrop на www.advancedqtp.com сайте . Если вы попытаетесь записать в свой тест движения DragAndDrop то ничего не получится , а этот пример покажет как можно это сделать:
|
|
|
Open QTP ( with web add-in ), Open a new test, open the object repository and add The Browser and Page to the local object repository. |
|
|
Rename the objects… |
|
|
Option Explicit Const LEFT_MOUSE_BUTTON = 0
Dim oWebElemDesc1, oWebElemDesc2 Dim oWebElem1, oWebElem2 Dim devRep Dim nX1, nX2, nY1, nY2, nH1, nH2, hwnd Dim point1, point2
' ** This class holds a point coordinate Class Point Private mX, mY Property Let X( ByVal value ) mX = value End Property Property Get X() X = mX End Property Property Let Y( ByVal value ) mY = value End Property Property Get Y() Y = mY End Property End Class
' ** Retrieving the handle of the browser hwnd = Browser("QTP").GetROProperty( "hwnd" ) Window( "hwnd:=" & hwnd ).Activate ' ** Create a description for 'Program Professionally’ Set oWebElemDesc1 = Description.Create() oWebElemDesc1( "micclass" ).Value = "WebElement" oWebElemDesc1( "html tag" ).Value = "H3″ oWebElemDesc1( "innertext" ).Value = "Program Professionally" oWebElemDesc1( "class" ).Value = "dbx-handle dbx-handle-cursor" ' ** Create a description for 'Links’ Set oWebElementDesc2 = Description.Create() oWebElemDesc2( "micclass" ).Value = "WebElement" oWebElemDesc2( "html tag" ).Value = "H3″ oWebElemDesc2( "innertext" ).Value = "Links" oWebElemDesc2( "class" ).Value = "dbx-handle dbx-handle-cursor" ' ** Searching for the elements With Browser( "QTP" ).Page( "QTP" ) If .ChildObjects( oWebElemDesc1 ).Count = 1 Then Set oWebElem1 = .WebElement( oWebElemDesc1 ) If .ChildObjects( oWebElemDesc2 ).Count = 1 Then Set oWebElem2 = .WebElement( oWebElemDesc2 ) Else Print "Web Element 'Program Professionally’ was not found." ExitTest( micFail ) End If Else Print "Web Element 'Program Professionally’ was not found." ExitTest( micFail ) End If End With ' ** Retrieve elements dimensions nX1 = oWebElem1.GetROProperty( "abs_x" ) nH1 = oWebElem1.GetROProperty( "height" ) nY1 = oWebElem1.GetROProperty( "abs_y" ) nX2 = oWebElem2.GetROProperty( "abs_x" ) nH2 = oWebElem2.GetROProperty( "height" ) nY2 = oWebElem2.GetROProperty( "abs_y" ) Set point1 = New Point point1.X = nX1 + 10 point1.Y = nY1 + nH1 - 10 Set point2 = New Point ' ** Dragging up If nY1 > nY2 Then point2.X = nX2 + 20 point2.Y = nY2 + nH2 - 20 Else ' ** Dragging down point2.X = nX2 + 20 point2.Y = nY2 + nH2 + 20 End If Set devRep = CreateObject( "Mercury.DeviceReplay" ) devRep.DragAndDrop point1.X, point1.Y, _ point2.X, point2.Y, LEFT_MOUSE_BUTTON |
|
MouseDblClick Method
|
|
Симуляция двойного левого/правого клика на экране. |
|
|
|
object.MouseDblClick( x, y, Button ) |
|
|
|
Parameter |
Description |
|
|
object |
Always a Mercury.DeviceReplay object |
|
|
x |
the x absolute coordinate in a screen for perform the double-click |
|
|
y |
the y absolute coordinate in a screen for perform the double-click |
|
|
button |
possible values LEFT_MOUSE_BUTTON = 0 MIDDLE_MOUSE_BUTTON = 1 RIGHT_MOUSE_BUTTON = 2 |
|
|
None |
|
|
|
|
|
MouseDown Method
|
|
Симуляция (постоянногo)левого/правого клика на экране. |
||
|
|
object.MouseDown( x, y, Button ) |
||
|
|
Parameter |
Description |
|
|
|
object |
Always a Mercury.DeviceReplay object |
|
|
|
x |
the x absolute coordinate in a screen for perform the click |
|
|
|
y |
the y absolute coordinate in a screen for perform the click |
|
|
|
button |
possible values LEFT_MOUSE_BUTTON = 0 MIDDLE_MOUSE_BUTTON = 1 RIGHT_MOUSE_BUTTON = 2 |
|
|
|
None |
||
|
|
|||
|
|
|
|
|
MouseUp Method
|
|
Метод освобождения : |
||
|
|
object.MouseDown( x, y, Button ) |
||
|
|
Parameter |
Description |
|
|
|
object |
Always a Mercury.DeviceReplay object |
|
|
|
x |
the x absolute coordinate in a screen for perform the mouse release |
|
|
|
y |
the y absolute coordinate in a screen for perform the mouse release |
|
|
|
button |
possible values LEFT_MOUSE_BUTTON = 0 MIDDLE_MOUSE_BUTTON = 1 RIGHT_MOUSE_BUTTON = 2 |
|
|
|
None |
||
|
|
|||
|
|
|
|
|
MouseMove Method
SetSynchronizationTimeout Method
|
|
Синхронизация времени действия |
||
|
|
object.MouseDown( x, y ) |
||
|
|
Parameter |
Description |
|
|
|
object |
Always a Mercury.DeviceReplay object |
|
|
|
nSyncTimeout |
the synchronization timeout |
|
|
|
is_sec |
Boolean value that indicates the nSyncTimeout is in seconds |
|
|
|
None |
||
|
|
|||
|
|
|
|
|
Key Codes Reference
Posted in QTP Techniques


Yaron Assa








February 25th, 2009 at 6:00 pm
Excelent! Thanks a lot! Helped to Set data into the Teleric masked control for the phone number!
Whish all QTP help would be written like this!
February 28th, 2009 at 5:13 pm
Realy a great work, thank you
March 27th, 2009 at 11:06 am
Thank you