context menu strip - select by item
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-04-2011
08:22 PM
01-04-2011
08:22 PM
context menu strip - select by item
I'm using Testcomplete in Version 8.0.290.7 since a few days. I'm mainly using keyword tests to test our GUI.
Therefore I have to simulate some clicks on context menus (concrete: clicks on context menu strips). If I record the test these clicks are recorded by the mousepointer position relative to the menu base point.
I would like to record them by the item name instead (for example: "Rename" instead of "10, 33") because the simple position would lead to a lot of errors in the case that our developers change positions or add new items to these menus?
Is this possible?
regards,
ricardo
Therefore I have to simulate some clicks on context menus (concrete: clicks on context menu strips). If I record the test these clicks are recorded by the mousepointer position relative to the menu base point.
I would like to record them by the item name instead (for example: "Rename" instead of "10, 33") because the simple position would lead to a lot of errors in the case that our developers change positions or add new items to these menus?
Is this possible?
regards,
ricardo
8 REPLIES 8
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-07-2011
12:31 AM
01-07-2011
12:31 AM
Hi Ricardo,
TestComplete has extended support for the standard context menu script and records actions with menu items using their captions by default. You can find more information in the StripPopupMenu Property help topic. To find out why this functionality does not work in your case, please provide us with more information:
1. Record a script test with the problematic menu and post this script here.
2. Let me know the exact value of the ClrFullClassName property of the context menu control. You can find the control and check its properties in the Object Browser panel.
3. Let me know exactly when the context menu control is created and bound to a GUI object in your application: when this GUI object is created or when it is right-clicked.
--
Dmitry Nikolaev
Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️
Dmitry Nikolaev
Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-07-2011
01:02 AM
01-07-2011
01:02 AM
Hallo David,
thanks for your help.
This is an example like it works at the moment.
Sub StripMenu()
'Clicks the '|Solution (stripMenu)|stripMenu|Basic' item of the 'ProjectOverviewTreeView' tree with the right mouse button.
Call Aliases.nxtSTUDIO.DefaultWorkbench1.ToolStripContainer.ToolStripContentPanel.Panel.DockPanel.DockWindow2.DockPane.PadContentWrapper.Panel.ProjectOverviewTreeView.ClickItemR("|Solution (stripMenu)|stripMenu|Basic")
'Clicks at point (26, 17) of the 'ContextMenuStrip' object.
Call Aliases.nxtSTUDIO.ContextMenuStrip.Click(26, 17)
'Moves the mouse cursor to the menu item specified and then simulates a single click.
Call Aliases.nxtSTUDIO.DefaultWorkbench1.StripMainMenu.Click("File|New|Solution...")
End Sub
Statement 2 is a problem in our tests because it click by coordinates. If a developer adds a new Item to the Menu, I will have to adapt all the tests.
What I'm searching for is a Method at the ContextStripMenu like in Statement 3, where I can choose the Item by a String.
(There is no problem by selecting the mentioned context menu.)
thanks for your help.
This is an example like it works at the moment.
Sub StripMenu()
'Clicks the '|Solution (stripMenu)|stripMenu|Basic' item of the 'ProjectOverviewTreeView' tree with the right mouse button.
Call Aliases.nxtSTUDIO.DefaultWorkbench1.ToolStripContainer.ToolStripContentPanel.Panel.DockPanel.DockWindow2.DockPane.PadContentWrapper.Panel.ProjectOverviewTreeView.ClickItemR("|Solution (stripMenu)|stripMenu|Basic")
'Clicks at point (26, 17) of the 'ContextMenuStrip' object.
Call Aliases.nxtSTUDIO.ContextMenuStrip.Click(26, 17)
'Moves the mouse cursor to the menu item specified and then simulates a single click.
Call Aliases.nxtSTUDIO.DefaultWorkbench1.StripMainMenu.Click("File|New|Solution...")
End Sub
Statement 2 is a problem in our tests because it click by coordinates. If a developer adds a new Item to the Menu, I will have to adapt all the tests.
What I'm searching for is a Method at the ContextStripMenu like in Statement 3, where I can choose the Item by a String.
(There is no problem by selecting the mentioned context menu.)
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-07-2011
02:20 AM
01-07-2011
02:20 AM
Hi Ricardo,
Thanks for information. However, could you please also tell
me about the value of the ClrFullClassName property and a way in which the
problematic menu object is created?
--
Dmitry Nikolaev
Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️
Dmitry Nikolaev
Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-07-2011
02:46 AM
01-07-2011
02:46 AM
This mentioned property value is
System.Windows.Forms.ContextMenuStrip
I hope this is the information you're searching for.
Thanks, Ricardo
System.Windows.Forms.ContextMenuStrip
I hope this is the information you're searching for.
Thanks, Ricardo
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-07-2011
03:26 AM
01-07-2011
03:26 AM
Hi Ricardo,
In this case, the latest possible cause of the problem I can imagine at the moment is that the menu object is created dynamically when the right mouse button is clicked, but not when the form is opened. Is this right?
--
Dmitry Nikolaev
Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️
Dmitry Nikolaev
Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-07-2011
03:31 AM
01-07-2011
03:31 AM
Yes this is possible ...Are there any solutions in this case?
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-08-2011
03:30 AM
01-08-2011
03:30 AM
Hi Ricardo,
It would be perfect if you described exactly how the menu control is bound to objects in your application so we can think about supporting this in the future.
In the meantime, you can use a custom script for selecting an item from the context menu:
...
'Clicks the '|Solution (stripMenu)|stripMenu|Basic' item of the 'ProjectOverviewTreeView' tree with the right mouse button.
Call Aliases.nxtSTUDIO.DefaultWorkbench1.ToolStripContainer.ToolStripContentPanel.Panel.DockPanel.DockWindow2.DockPane.PadContentWrapper.Panel.ProjectOverviewTreeView.ClickItemR("|Solution (stripMenu)|stripMenu|Basic")
'Clicks at point (26, 17) of the 'ContextMenuStrip' object.
Call ClickMenuItem(Aliases.nxtSTUDIO.ContextMenuStrip, "Rename")
...
Function ClickMenuItem(menu, path)
Dim i, items, item, found, x, y, point
items = Split(path, "|")
' Find the menu item to click
found = False
For i = 0 To menu.Items.Count - 1
Set item = menu.Items.Item(i)
If item.Text.OleValue = items(0) Then
found = true
Exit For
End If
Next
If Not found Then
Log.Error "The '" & items(0) & "' menu item is not found"
ClickMenuItem = False
Exit Function
End If
' Calculate the menu item's screen coordinates and click
Set point = menu.PointToScreen(item.Bounds.Location)
x = point.X + item.Bounds.Width / 2
y = point.Y + item.Bounds.Height / 2
Call Sys.Desktop.MouseDown(VK_LBUTTON, x, y)
Call Sys.Desktop.MouseUp(VK_LBUTTON, x, y)
Delay 250
' Proceed to the next item in the path
If UBound(items) > 0 Then
ReDim newPath(UBound(items) - 1)
For i = 0 To UBound(newPath)
newPath(i) = items(i + 1)
Next
If Not ClickMenuItem(item.DropDown, Join(newPath, "|")) Then
ClickMenuItem = False
Exit Function
End If
End If
ClickMenuItem = True
End Function
--
Dmitry Nikolaev
Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️
Dmitry Nikolaev
Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-29-2017
12:11 AM
11-29-2017
12:11 AM
Hi Dmitry_Nikolaev,
Thank you for the code that you had given for Ricardo's situation. I did have the exact same problem where the context menu was created on the fly and TC could not identify the items on the context menu. I used the provided custom script to select an item and it worked fine. However, is there a proper or an updated way to handle such situation easily by TC? How can the keyword test be adapted for such situation? Is there a solution already?
Thank you.
Sudha
