In Silk Test Workbench how can I move the mouse cursor relative to the desktop?
Typically if you want to move the mouse cursor in SilkTest, you would use a control as a basis for calculating the co-ordinates for the location of where the mouse is to be moved. For example the following VB.Net sub routine demonstrates how I called the method “GetRect” against the “TreeView” dialog box shown below, in order to return the coordinates for where I wish to move the mouse.
Public Sub GetRectTest()
Dim intNo As Integer = 0
With _desktop.Window("@caption='Test Application'")
With .Dialog("@caption='Tree View'")
.SetActive()
myRect = .Tree("@caption='The Tree View'").GetRect()
.MouseMove(New Point(myRect.x,myRect.y))
While intNo <105
.MouseMove(New Point(myRect.x+25,myRect.y+IntNo))
.Click(MouseButton.Left, New Point(myRect.x+25,myRect.y+IntNo))
intNo = intNo +15
End While
End With
End With
End Sub
When the sub routine is executed it will move the mouse and then click on each of the “Tree” elements; it does this by adding 25 pixels to the x coordinate for each iteration of the While loop.
However such scenarios may arise, where you are either not able to identify an object to call the GetRect() method against or you need to get the coordinates from the current mouse cursor position as it appears on the desktop. In such scenarios you will have to do the following in the SilkTest Workbench.
1) Create a “New Application Configuration” for the Windows Desktop; this can be done by hooking the “Explorer.exe”
2) Minimize all windows on the desktop, then from SilkTest Workbench start the “Identify Object” tool to identify the Windows OS Desktop, like so:
3) Use the “Cursor” class in .NET to return the current position of the cursor to the type “Point”. The VB.NET script below demonstrates how to do this:
Imports SilkTest.Ntf
Imports SilkTest.Ntf.Win32
Public Module Main
Dim _desktop As Desktop = Agent.Desktop
Public Sub GetCursorFromDesktop()
'Create new variable to hold the coordinates of type Point
Dim cursorPosition As System.Drawing.Point
Dim intNumber As Integer = 0
'The code below is used to simply hover the mouse over a control so as
'the mouse cursor is where I want it to be on the desktop for testing purposes
With _desktop.Window("@caption='Test Application'")
With .Dialog("@caption='Tree View'")
.SetActive()
.Tree("@caption='The Tree View'").MouseMove(New Point(20,5))
System.Threading.Thread.Sleep(2000)
'Get the current Cursor position on the desktop by calling the “Position” property
cursorPosition = System.Windows.Forms.Cursor.Position
End With
End With
'Hook into the desktop so that the move mouse actions are performed
'relative to desktop as opposed to relative to a specific control or AUT
With _desktop.ListView("/Control[@caption='Program Manager']//ListView")
.MouseMove(New Point(cursorPosition.x,cursorPosition.y))
While intNumber <100
.MouseMove(New Point(cursorPosition.x+25,cursorPosition.y+intNumber))
.Click(MouseButton.Left, New Point(cursorPosition.x+25,cursorPosition.y+intNumber))
intNumber = intNumber +15
End While
End With
End Sub
Public Sub Main()
'Get the Sub routine
GetCursorFromDesktop()
End Sub
End Module
When executed, like the Sub routine “GetRectTest()” the code will iterate through each of the “Tree” Elements, however unlike that Sub routine, the cursor position used will be relative to the desktop and not the control identified as “Tree("@caption='The Tree View'")”