Automation of the .NET ToolbarsManager

If you use QTP for automating .NET apps and the app is built using infragistics, you know that it is not easy to use the .NET spy . After a lot of effort I was able to find solution to perform operations on a infragistics toolbar where the swftoobar object was getting identified as a swfobject:

Here is the code how to work with .net toolbarsmanager:

set cToolbars = SwfWindow("").SwfObject("").Object.ToolbarsManager.Toolbars
Set oMyTool = GetToolFromToolbar(cToolbars,"", "")
omyTool. 'Operation you want

Function GetToolFromToolbar(byref cToolbars, sToolbarKey, sToolKey)
   Dim oToolbar ' Toolbar object
   Dim bToolbarFound
   Dim bToolFound

   bToolbarFound = false
   bToolFound = false

   For x = 0 to cToolbars.Count - 1
      If sToolbarKey = cToolbars.GetItem(x).Key Then
          set oToolbar = cToolbars.GetItem(x)
          bToolbarFound = true
          Exit for
      End If
   Next

   If bToolbarFound = true Then
       For x = 0 to oToolbar.Tools.Count - 1
           If sToolKey = oToolbar.Tools.GetItem(x).Key Then
                 Set GetToolFromToolbar = oToolbar.Tools.GetItem(x)
                 bToolFound = true
                 Exit for
           End If
       Next

       If bToolFound = false Then
       msgbox"Tool Not Found"
    End If
  End If
End Function

And if you are lucky that the toolbar is recognized as swftoolbar then its easier:

set obj = SwfWindow("SwfWindow").SwfToolbar("SwfToolbar").Object.Buttons
msgbox obj.Count
For i = 1 to obj.Count   
    msgbox obj.Item(i).tooltiptext // or any other operation
Next

Comments

  1. Anonymous20/5/11

    What method i hav to used to click on a menu eg File->window new

    I hav tried select, click but not working...

    regards

    ReplyDelete
  2. Is the toolbar getting recognized as swftoolbar?
    In that case something like this should work:
    SwfWindow("").SwfToolbar("").Select "File;New"
    If not do u have shortcuts assigned to your menu , you can use them using sendkeys or :
    SwfWindow("").Type micAltDwn + "c" + micAltUp

    SwfWindow("").SwfToolbar("").ClickToolbarTool "MenuBar","File"


    SwfWindow("").SwfToolbar("").ShowDropdown ""

    ReplyDelete
  3. Anonymous20/5/11

    No its a swfobject....is there is any methods is availiable to click on a menu eg as suggested by u...oMytool.select.

    ReplyDelete
  4. Anonymous20/5/11

    Also we don't hav any short cut key to access the menu items....

    ReplyDelete
  5. Sorry about the late reply was a lil busy, If you havent solved ur issue, here is the soln:

    Set Mnubar = SwfWindow("").SwfObject("").Object.CommandLinks

    For i = 0 To Mnubar.Count -1
    Mnuname=Mnubar.Item(i).Text
    msgbox Mnuname
    oBounds = Mnubar.Item(i).Bounds
    arrBounds = Split(oBounds, ",")
    arrBound = Split(arrBounds(0), "=")
    iX = CInt(arrBound(1))
    arrBound = Split(arrBounds(1), "=")
    iY = CInt(arrBound(1))
    SwfWindow("").Activate
    SwfWindow("").SwfObject("").Click iX,iY

    ReplyDelete
  6. Anonymous24/5/11

    Thanks for your Reply...

    My toolbar is of control-Infragistics.Win.UltraWinToolbars.UltraToolbarsDockArea

    I have tried your code but commandlinks method is not populated bec of which i am unable to apply the same.

    regards

    ReplyDelete
  7. Try the soln frm the below link and let me know how far you go with it:

    http://www.advancedqtp.com/knowledge-base/articles/environment-techniques-id15/net-id173/exploring-custom-controls/

    ReplyDelete

Post a Comment

Popular posts from this blog

XPATH for IE / internet explorer

Website's underlying technology for automation

All time good software testing books!