How to work with right-click context/popup menus in SilkTest?
An alternative to using coordinates to specify where SilkTest should click on a menu item in a context/popup menu is to use the GetItemRect() function to get the coordinates of the context/popup menu, then call PopupSelect() to select a menu item.
A drawback of this is that to use the GetItemRect() function, we need the Classic Agent, therefore, if the application under test is required to be tested using the Open Agent, we have to record the windows declaration of the application using the Classic Agent also. As we only need the windows declaration for the actions we wish to perform on the context/popup menu, we can record actions to generate this declaration.
Once the Classic Agent declarations are complete, we can then revert back to the Open Agent to continue our tests. Purpose of the windows declaration for the Classic Agent is to allow SilkTest to handle the actions we wish to perform that require Classic Agent only functions.
We will test against the Computer Manager (MMC) application in Windows. The following testcase navigates to the "Removable storage" treenode, then right-clicks on the treenode item and from the context/popup menu, we select "Properties". The Open Agent window declaration is what we use to perform the intial actions of navigating the treeview object. Then using the Classic Agent declarations, we can call the GetItemRect() function as shown below.
Open Agent declaration:
window MainWin ComputerManagement
// The working directory of the application when it is invoked
const sDir = "C:\"
Classic Agent declaration (recorded only from actions performed on the treeview node object):
window DialogBox ComputerManagement1
tag "Computer Management"
window ChildWin ComputerManagementLocalSt
tag "Computer Management (Local)\Storage\Removable Storage"
Testcase to perform required actions:
// declare variable to be used in the testcase
WINDOW wTree = ComputerManagement.Control1.ComputerManagementLocalSt.Control1.TreeView1 // TreeView object
STRING sNode = "/Computer Management (Local)/Storage"
STRING sTreeNode = "/Computer Management (Local)/Storage/Removable Storage"
STRING sMenuItem = "Properties"
// expand necessary treenode
// select the treenode
// right-click using the keyboard context menu key
// recorded declaration with classic agent
// use RECT data type to get screen position of the context/popup menu
iRect = ComputerManagementLocalSt.MMCViewWindow1.TreeView1.GetItemRect(sTreeNode)
// focusing on the screen position retrieved from iRect, click on the menuitem
ComputerManagementLocalSt.MMCViewWindow1.TreeView1.PopupSelect(iRect.xPos, iRect.yPos, sMenuItem)
* The testscript will be run using the Open Agent, but Silktest will know when a Classic Agent declaration is in use and will revert to the Classic Agent when required and vice versa.