揭秘QTP的DeviceReplay对象[转]

上一篇 / 下一篇  2010-09-20 13:30:10 / 个人分类:QTP

揭秘QTPDeviceReplay对象
不知道为什么HP的帮助文档中没有提供关于DeviceReplay的强大功能的信息描述。你可以在Java插件中却可以找到DeviceReplay的属性,但是对于那些不使用Java插件的人可能会觉得这个对象仅在Java程序的测试中可用。

  为什么要用DeviceReplay?

  有些时候我们需要针对界面做一些指定的动作,例如右键单击一个对象,使用功能键(Fx)来激活某些热键的功能,这时候就可以使用DeviceReplay对象,或者在Object.Set和Object.Type方法不生效时使用DeviceReplay。

  并且DeviceReplay在输入特殊符号以及不同语言的文字时会很有用,因为不需要安装指定的字体或改变键盘 布局,这对于测试多语言环境的应用程序会非常有用。

  在鼠标 操作方面,我发现DragDrop方法非常有用,可以使用它来执行拖拽的操作,把一个Item从一个Frame拖动到另外一个Frame,或者在应用程序之间拖动。

  Mercury.DeviceReplay对象

  Mercury.DeviceReplay对象用于模拟鼠标单击和移动,还有键盘输入等操作。要使用DeviceReplay,你必须确保被测试的应用程序(AUT)是处于激活状态的窗口。如果你想对某个对象执行一项操作,则该对象必须拥有焦点(focus)。对于Windows应用程序,可以使用 Activate方法:

  Window( "W" ).Activate micLeftBtn

  如果想把焦点设置到某个指定的对象上,通常使用Click方法可以完成。

  对于Web环境的应用程序,Activate方法不被支持,因此可以使用下面的技巧来完成:

  hwnd = Browser( "B" ).GetROProperty( "hwnd" )

  Window( "hwnd:=" & hwnd ).Activate micLeftBtn

  通常可以使用FireEvent “onfocusin”或object.focus,例如WebEdit(“WE”).Object.focus或WebEdit(“WE”)。FireEvent “onfocusin”。

  在调用DeviceReplay对象的方法之前,你需要首先创建DeviceReplay对象:

  Set deviceReplay = CreateObject( "Mercury.DeviceReplay" )

  Microsoft.VisualBasic.Devices.Keyboard类

  为什么我要在介绍DeviceReplay对象之前介绍这个.NET的类呢?DeviceReplay是一个强大的未被文档化的对象,但是有一定的局限性。其中一个局限就是不能判断一个Control键是否已经被按下。在输入一个大写字母之前,我们需要知道CAPS-LOCK键是否已经按下。在使用数字键盘之前我们需要检查NUM-LOCK键是否已经被按下。否则我们在切换键盘输入状态时可能得到的并不是我们想要的状态。

  Devices.Keyboard类提供了属性,可用于获取当前的键盘状态,例如当前什么键被按下了,并且提供一个方法用于向激活的窗口发送键盘敲击事件。

  几个有用的属性包括:

  AltKeyDown - 判断ALT键是否处于按下状态。

  CapsLock - 判断CAPS LOCK键是否处于打开状态。

  CtrlKeyDown - 判断CTRL 键是否处于按下状态。

  NumLock - 判断NUM LOCK键是否处于打开状态。

  ScrollLock - 判断SCROLL LOCK键是否处于打开状态。

  ShiftKeyDown - 判断SHIFT键是否处于按下状态。

  Set Keyboard = DotNetFactory.CreateInstance(

  "Microsoft.VisualBasic.Devices.Keyboard", "Microsoft.VisualBasic" )

  Print CBool( Keyboard.AltKeyDown )

  Print CBool( Keyboard.CapsLock )

  Print CBool( Keyboard.CtrlKeyDown )

  Print CBool( Keyboard.NumLock )

  Print CBool( Keyboard.ScrollLock )

  Print CBool( Keyboard.ShiftKeyDown )

  注意:在使用DotNetFactory时数据类型必须被转换

  System.Windows.Forms.Control 类

  DeviceReplay的另外一个局限是不能获取当前鼠标(光标)在屏幕 的位置。而System.Windows.Forms.Control这个类定义了那些拥有视觉表现的控件的基类。

  通过MousePosition属性可以获取当前鼠标光标在屏幕坐标的位置。访问MousePosition属性时,可以返回代表鼠标光标位置的Point数据。

  我的鼠标在哪?

  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的方法

  SendString方法

  描述

  向激活的窗口发送一个或多个键盘 按键,就像敲击键盘一样。

  语法

  object.SendString( str )

  参数

  object : Mercury.DeviceReplay对象。

  str : 敲击的字符串。

  返回值

  无。

  例子

  下面的例子会激活记事本(notepad)并输入一段字符:

  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方法

  描述

  模拟一个按键的按下并保持(相当于Win32的KEY_DOWN事件)。

  语法

  object.KeyDown( key )

  参数

  object : Mercury.DeviceReplay对象。

  key : 按键的数值码。可查阅后面的“Key Codes 参考”。

  返回值

  无。

  例子

  下面的例子会激活记事本(notepad)程序并使用大写和小写的方式输入字符串。注意在发送第一个字符串时,SHIFT键保持被按下的状态:

  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

  提示

  在KeyDown后应该有相应的KeyUp方法的调用。

  KeyDown方法就像人工按下一个按键并保持按下的状态。

  KeyUp方法

  描述

  模拟通过键盘释放某个按下的按键。

  语法

  object.KeyUp( key )

  参数

  object : Mercury.DeviceReplay对象。

  key : 按键的数值码。可查阅后面的“Key Codes 参考”。

  返回值

  无。

  例子

  下面的例子会激活并并使用热键CTRL+O来打开记事本(notepad)的菜单,然后用ESC键关闭对话框。

  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

  提示

  KeyUp方法应该与KeyDown方法配对使用。

  多个KeyUp不会对应用程序造成影响。

  如果需要组合热键,仅需要像人工执行的方式一样即可。

  PressKey方法

  描述

  模拟通过键盘按下一个按键并立即释放。

  语法

  object.PressKey( key )

  参数

  object : Mercury.DeviceReplay对象。

  key : 按键的数值码。可查阅后面的“Key Codes 参考”。

  返回值

  无。

  例子

  下面的例子会激活记事本并使用热键CTRL+O来模拟选择文件打开菜单,然后用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方法

  描述

  模拟通过键盘 多次按下一个按键并立即释放。

  语法

  object.PressNKey( key, N )

  参数

  object : Mercury.DeviceReplay对象。

  key : 按键的数值码。可查阅后面的“Key Codes 参考”。

  N:重复的次数。

  返回值

  无。

  例子

  例1 – 美国的州

  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 "United States of America"

  deviceReplay.PressKey VK_RETURN

  deviceReplay.PressNKeys VK_TAB, 3

  deviceReplay.PressNKeys VK_MULTIPLY, Len( "United States of America" )

  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( "Alabama", "AL", "Montgomery" )

  Call PrintRow( "Alaska", "AK", "Juneau" )

  Call PrintRow( "Arizona", "AZ", "Phoenix" )

  Call PrintRow( "Arkansas", "AR", "Little Rock" )

  Call PrintRow( "California", "CA", "Sacramento" )

  Call PrintRow( "Colorado", "CO", "Denver" )

  Call PrintRow( "Connecticut", "CT", "Hartford" )

  Call PrintRow( "Delaware", "DE", "Dover" )

  Call PrintRow( "Florida", "FL", "Tallahassee" )

  Call PrintRow( "Georgia", "GA", "Atlanta" )

  Call PrintRow( "Hawaii", "HA", "Honolulu" )

  Call PrintRow( "Idaho", "ID", "Boise" )

  Call PrintRow( "Illinois", "IL", "Springfield" )

  Call PrintRow( "Indiana", "IN", "Indianapolis" )

  Call PrintRow( "Iowa", "IA", "Des Moines" )

  Call PrintRow( "Kansas", "KS", "Topeka" )

  Call PrintRow( "Kentucky", "KY", "Frankfort" )

  Call PrintRow( "Louisiana", "LA", "Baton Rouge" )

  Call PrintRow( "Maine", "ME", "Augusta" )

  Call PrintRow( "Maryland", "MD", "Annapolis" )

  Call PrintRow( "Massachusetts", "MA", "Boston" )

  Call PrintRow( "Michigan", "MI", "Lansing" )

  Call PrintRow( "Minnesota", "MN", "Saint Paul" )

  Call PrintRow( "Mississippi", "MS", "Jackson" )

  Call PrintRow( "Missouri", "MO", "Jefferson City" )

  Call PrintRow( "Montana", "MT", "Helena" )

  Call PrintRow( "Nebraska", "NE", "Lincoln" )

  Call PrintRow( "Nevada", "NV", "Carson City" )

  Call PrintRow( "New Hampshire", "NH", "Concord" )

  Call PrintRow( "New Jersey", "NJ", "Trenton" )

  Call PrintRow( "New Mexico", "NM", "Santa Fe" )

  Call PrintRow( "New York", "NY", "Albany" )

  Call PrintRow( "North Carolina", "NC", "Raleigh" )

  Call PrintRow( "North Dakota", "ND", "Bismarck" )

  Call PrintRow( "Ohio", "OH", "Columbus" )

  Call PrintRow( "Oklahoma", "OK", "Oklahoma City" )

  Call PrintRow( "Oregon", "OR", "Salem" )

  Call PrintRow( "Pennsylvania", "PA", "Harrisburg" )

  Call PrintRow( "Rhode Island", "RI", "Providence" )

  Call PrintRow( "South Carolina", "SC", "Columbia" )

  Call PrintRow( "South Dakota", "SD", "Pierre" )

  Call PrintRow( "Tennessee", "TN", "Nashville" )

  Call PrintRow( "Texas", "TX", "Austin" )

  Call PrintRow( "Utah", "UT", "Salt Lake City" )

  Call PrintRow( "Vermont", "VT", "Montpelier" )

  Call PrintRow( "Virginia", "VA", "Richmond" )

  Call PrintRow( "Washington", "WA", "Olympia" )

  Call PrintRow( "West Virginia", "WV", "Charleston" )

  Call PrintRow( "Wisconsin", "WI", "Madison" )

  Call PrintRow( "Wyoming", "WY", "Cheyenne" )

  Set deviceReplay = Nothing

  例2 – 拉丁文和字符

  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方法

  描述

  用于执行从一点拖动到另外一点的操作。

  语法

  object.DragAndDrop( dragX, dragY, dropX, dropY, Button )

  参数

  object : Mercury.DeviceReplay对象。

  dragX :起点坐标的X轴的值。

  dragY :起点坐标的Y轴的值。

  dropX :终点坐标的X轴的值。

  dropY :终点坐标的Y轴的值。

  Button :可能的值包括

  LEFT_MOUSE_BUTTON = 0

  MIDDLE_MOUSE_BUTTON = 1

  RIGHT_MOUSE_BUTTON = 2

  返回值

  无。

  提示

  可以组合使用MouseDown、MouseMove和MouseUp方法。

MouseClick方法

  描述

  在指定的屏幕 位置执行鼠标 左键或右键的单击操作。

  语法

  object.MouseClick( x, y, Button )

  参数

  object : Mercury.DeviceReplay对象。

  x :屏幕坐标X轴的值。

  y :屏幕坐标Y轴的值。

  Button :可能的值包括

  LEFT_MOUSE_BUTTON = 0

  MIDDLE_MOUSE_BUTTON = 1

  RIGHT_MOUSE_BUTTON = 2

  返回值

  无。

  例子

  下面的例子在执行之前需要做一定的准备工作。例子的目的是在www.advancedqtp.com网站上执行DragAndDrop操作,如果在录制时执行拖拽操作,则不会被录制下来。因此这个例子是支持某些操作的例子。这个例子在IE环境下测试通过。

  打开IE浏览器并导航到www.advancedqtp.com。这个例子会交换dbxhandle项,这些对象可以被拖拽以便满足个性化显示的要求。

 
  打开QTP(加载Web插件),新建一个测试,打开对象库(object repository)并添加浏览器中的页面对象到本地对象库(local object repository)中。

 
  重命名对象…

 
  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

  MouseDbClick方法

  描述

  在指定的屏幕位置中执行鼠标左键或右键的双击事件。

  语法

  object.MouseDblClick( x, y, Button )

  参数

  object : Mercury.DeviceReplay对象。

  x :屏幕坐标X轴的值。

  y :屏幕坐标Y轴的值。

  Button :可能的值包括

  LEFT_MOUSE_BUTTON = 0

  MIDDLE_MOUSE_BUTTON = 1

  RIGHT_MOUSE_BUTTON = 2

  返回值

  无

MouseDown方法

  描述

  在屏幕 指定位置按下鼠标 左键或右键,并保持按下状态。

  语法

  object.MouseDown( x, y, Button )

  参数

  object : Mercury.DeviceReplay对象。

  x :屏幕坐标X轴的值。

  y :屏幕坐标Y轴的值。

  Button :可能的值包括

  LEFT_MOUSE_BUTTON = 0

  MIDDLE_MOUSE_BUTTON = 1

  RIGHT_MOUSE_BUTTON = 2

  返回值

  无

  提示

  应该在MouseDown后使用对应的MouseUp方法。

  MouseUp方法

  描述

  用于释放之前执行的MouseDown方法所按下的鼠标按键。

  语法

  object.MouseDown( x, y, Button )

  参数

  object : Mercury.DeviceReplay对象。

  x :屏幕坐标X轴的值。

  y :屏幕坐标Y轴的值。

  Button :可能的值包括

  LEFT_MOUSE_BUTTON = 0

  MIDDLE_MOUSE_BUTTON = 1

  RIGHT_MOUSE_BUTTON = 2

  返回值

  无

  提示

  应该让MouseUp和MouseDowun方法配对使用。

  MouseMove方法

  描述

  用于模拟鼠标移动。

  语法

  object.MouseMove( x, y )

  参数

  object : Mercury.DeviceReplay对象。

  x :屏幕坐标X轴的值。

  y :屏幕坐标Y轴的值。

  返回值

  无

  提示

  调试脚本查看在运行时获取到的坐标位置。

  在执行键盘 操作之前移动鼠标到指定的位置并设置焦点。

  SetSynchronizationTimeout方法

  描述

  设置一个新的同步超时的时间值。

  语法

  object. SetSynchronizationTimeout(nSyncTimeout , is_sec)

  参数

  object : Mercury.DeviceReplay对象。

  nSyncTimeout : 同步超时的时间值。

  is_sec : 指定设置的时间值是否以秒为单位。

  返回值

  无

  提示

  建议不要修改这个值。


TAG: DeviceReplay QTP qtp 模拟键盘 模拟鼠标

 

评分:0

我来说两句

testlab

testlab

这个人很懒,什么都没留下

我的栏目

日历

« 2024-04-24  
 123456
78910111213
14151617181920
21222324252627
282930    

数据统计

  • 访问量: 6481
  • 日志数: 4
  • 建立时间: 2009-09-04
  • 更新时间: 2010-12-06

RSS订阅

Open Toolbar