Forum Discussion
While I don't recommend keeping unedited Mappings and code from a recording for your final test, have you tried recording interacting with the context menu? What happens when you use Object Spy?
When we recorded keyword tests, the recording would save the wrong objects from name-mapping. It was over a year-ago and my memory is a little vague, but the results were not what we expected, and we had trouble discerning what we needed.
Here's a Test Visualizer image of the context menu's. I believe this was produced with the code below.
Three level context menu accessed by right-clicking on an object
Sample Code:
This is the code where we left-off. Maybe it will give you some ideas.
The code:
#. Set the scroll position
#. right-click an item in a listbox to cause the 1st level context menu to popup
#. Call FindAll on PopupRoot and call FindAll of the result to log the results for viewing/debugging (trying to find accessible objects)
#. Hover the mouse over 1st level menu (looks like the coordinates are hard-coded)
#. Determine positionally (x,y) where level 2 submenu is
#. Hover the mouse over the level 2 submenu to cause the 3rd level menu to popup
#. Determine the position of an item in the 3rd level menu by adding the width of the 2nd level menu
#. Click on the determined position
Hopefully this will help you find a path forward. I'm sure we will need to revisit this in the future. We desperately need a solution. We use context menu's in many places.
# Script is not complete. # TODO: need to figure out way to access multi-level context menu items import ScriptGetMCU def SystemDiagramOnline1(): Aliases.CrewWare.HwndSource_mainWindow.mainWindow.tabControl1.scrollViewer1.VScroll.Pos = 0 Aliases.CrewWare.HwndSource_mainWindow.mainWindow.tabControl1.scrollViewer1.HScroll.Pos = 0 x = ScriptGetMCU.GetMCUIndex() Aliases.CrewWare.HwndSource_mainWindow.mainWindow.tabControl1.listBoxDevices.ClickItemR(x) # Attempting to figure out how to access context menu items by names, so far unsuccessful arrayproperties=["ClrClassName"] arrayvalues=["*"] something = Aliases.CrewWare.HwndSource_PopupRoot.PopupRoot.FindAll(arrayproperties, arrayvalues, 100, True) for x in range(len(something)): Log.Message("something[" + str(x) + "]" + something[x].ClrClassName + ", " + something[x].Name) somethingelse = something[x].FindAll(arrayproperties, arrayvalues, 100, True) for y in range(len(somethingelse)): Log.Message("somethingelse[" + str(y) + "]" + somethingelse[y].ClrClassName + ", " + somethingelse[y].Name) contextmenu = Aliases.CrewWare.HwndSource_PopupRoot.PopupRoot contextmenu.HoverMouse(60, 100) Delay(500) #Submenu1 mouseX = Sys.Desktop.MouseX mouseY = Sys.Desktop.MouseY mouseX = mouseX + contextmenu.Width submenu1 = Sys.ObjectFromPoint(mouseX, mouseY) objectPoint = submenu1.ScreenToWindow(mouseX, mouseY) submenu1.HoverMouse(objectPoint.X, objectPoint.Y) Delay(500) #Submenu2 mouseX = Sys.Desktop.MouseX mouseY = Sys.Desktop.MouseY mouseX = mouseX + submenu1.Width submenu2 = Sys.ObjectFromPoint(mouseX, mouseY) objectPoint = submenu2.ScreenToWindow(mouseX, mouseY) Delay(500) submenu2.Click(objectPoint.X, objectPoint.Y)
- brohrbacher6 years agoOccasional Contributor
Thanks for the information. We also use a lot of context menus in our software. My current workaround is to use the X,Y coordinates within the context menu. Not ideal but it will work for the time being.
I reached out to support to see if there is something I am missing and/or not understanding. It could be an issue with TestComplete dealing with complex context menus. I ran their notepad example https://support.smartbear.com/testcomplete/docs/app-objects/specific-tasks/standard/menu/displaying-context.html and that seemed to work just fine. I tried replicating what they did within our software but I had no luck. Even had one of the developers take a look and they were stumped and just suggested I use the X,Y coordinates.
I will keep you updated if I hear anything.
Related Content
- 11 years ago
- 4 years ago
Recent Discussions
- 18 hours ago