Forum Discussion

ricardo's avatar
ricardo
New Contributor
14 years ago

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

8 Replies


  • 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

  • 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.
  • ricardo's avatar
    ricardo
    New Contributor
    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.)
  • 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?

  • ricardo's avatar
    ricardo
    New Contributor
    This mentioned property value is



    System.Windows.Forms.ContextMenuStrip



    I hope this is the information you're searching for.



    Thanks, Ricardo

  • 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?
  • ricardo's avatar
    ricardo
    New Contributor
    Yes this is possible ...Are there any solutions in this case?
  • Hi