Forum Discussion

vex's avatar
vex
Contributor
13 years ago

Does TC Support this control?

Does TestComplete support the Yahoo.widget.TreeView ?  See here: http://developer.yahoo.com/yui/docs/YAHOO.widget.TreeView.html



We have a webapp that uses this for file/folder listings and my goodness it seems almost impossible to wrap my head around this.  I think the expand node had 45 parents.  Is there native TC support for this control?



I tried taking the HTML of the control and parsing it through a custom written controller for it and..  well my skills aren't that good I guess, because I couldn't wrap my head around it.  Does anyone have any kind of suggestion on how I can code something for this control?  I want to be able to traverse it and select and deselect items at will similar to a Win32 treeview.



I tried to add this under Object Mapping > Swing Controls > Tree, but it doesn't meet the criteria.
  • vex's avatar
    vex
    Contributor
    Ok so I took a different approach using FindAllChildren.



    I'm making HUGE progress here, but I'm still running into a snag.  In order for this to work right, I have to expand all of the folder nodes of the tree first.  No biggie, since all of the + nodes have a className = ygtvspacer and are in their own cells/tables.



    But..  Oddly enough, tehre are more than 500 items that should match this, but TC only finds like 6... sometimes just 3... what's wrong with this code?



    PropArray      = Array("className")

      ValuesArray    = Array("ygtvspacer")



      Set pnlData    = Aliases.WebBrowser.page.panelContainer.form.panelContent.FileFolderList

     

      ndeFolder      = pnlData.FindAllChildren(PropArray, ValuesArray, 20000, True)



      For i = 0 to UBound(ndeFolder)

        If ndeFolder(i).Exists Then ndeFolder(i).Click

      Next

       

      Log.Message "Total Found: " & (UBound(ndeFolder) + 1)

  • Julia_K's avatar
    Julia_K
    SmartBear Alumni (Retired)

    Hello Vince,


    Does TestComplete support the Yahoo.widget.TreeView ?


    Currently, TestComplete does not support this control.  If you are interested in implementing support for this control (and other Yahoo controls) in TestComplete, you can vote for this control on the following web page: TestComplete Feature Survey.

    Thank you.


    Oddly enough, tehre are more than 500 items that should match this, but TC only finds like 6... sometimes just 3... what's wrong with this code?


    I failed to reproduce the behavior you describe. This problem may be specific to your application under test. Could you please use this Contact Support web form to send us your project and application (or a sample application demonstrating the problem)? That would help us to reproduce the problem.

    Thanks in advance.


    Also, to access items of the tree view, you can try finding them by their class name (ygtvitem) or caption text (specified by the innerText property). For example, the following sample code iterates through tree view items and expands them if they are collapsed:



    Sub Test

      URL = http://developer.yahoo.com/yui/examples/treeview/folder_style_clean.html

      ' Obtains the tree view object and processes all of its items

      Set TreeObj = Sys.Process("iexplore").Page(URL).Panel("treeDiv1").Panel("ygtv0").Panel("ygtvc0")

      ProcessItems(TreeObj)

    End Sub



    Sub ProcessItems(Obj)

      Dim PropArray, ValuesArray, Children, InnerChildren, Table, Spacer

      PropArray = Array("className")

      ValuesArray = Array("ygtvitem")

      ' Obtains the collection of tree view items 

      Children = Obj.FindAllChildren(PropArray, ValuesArray, 1)

      For i = 0 To Ubound(Children)

        ' Checks whether the item has child subitems 

        PropArray = Array("className")

        ValuesArray = Array("ygtvchildren")

        Set InnerChildren = Children(i).FindChild(PropArray, ValuesArray, 1)

        If InnerChildren.Exists Then

          If InnerChildren.ChildCount > 0 Then

          ' Checks whether the subitems are visible on the screen

            If Not InnerChildren.VisibleOnScreen Then

              If Not InnerChildren.Visible Then

                PropArray = Array("className")

                ValuesArray = Array("ygtvtable*")

                Set Table = Children(i).FindChild(PropArray, ValuesArray, 1)

                If Table.Exists Then

                  PropArray = Array("className")

                  ValuesArray = Array("ygtvspacer")

                  Set Spacer = Table.FindChild(PropArray, ValuesArray, 2)

                  If Spacer.Exists Then

                    ' Expands the item

                    Spacer.Click

                  End If

                End If

              End If

            End If

            ' Processes the current item's subitems

            ProcessItems(InnerChildren)

          End If  

        End If

      Next

    End Sub


    Or instead of the FindAllChildren method you can use the EvaluateXPath method to get tree view items.

    For example, the following sample code obtains all A elements whose class attribute is set to "ygtvspacer" and then simulates a click on each element:



    Sub Test

      URL = "http://developer.yahoo.com/yui/examples/treeview/folder_style_clean.html" 

      Set Page = Sys.Process("iexplore").Page(URL)  

      Nodes = Page.EvaluateXPath("//A[@class='ygtvspacer']")  

      If VarType(Nodes) <> varNull Then  

        For i = 0 To UBound(Nodes)

          Nodes(i).Click

        Next    

      End If

    End Sub


    I hope this information helps you. Please let us know if you have any additional questions.

    Good luck.

  • vex's avatar
    vex
    Contributor
    Julia,



    This is incredible help.  Thank you so much.  Voted to have YUI support btw.



    I'm gonna work on tailoring this into my app and see if I run into better luck.  The problem with my original FindAllChildren and why it kept finding different results was due to the fact that the YUI control apparently hides (or something?) objects that aren't expanded.  For example, if I left it uncollapsed it might only find 3 objects, but if I expanded some nodes, it might find 15-20 objects.



    The key is to expand all objects first, find what I'm looking for, and expand click on the object to show the file.  At least until TC gets some level of support in for this control, which hopefully will happen in the future.



    Thanks again Julia for the help here.  Much, much appreciated :).
  • vex's avatar
    vex
    Contributor
    So I tried your code to try to understand it better .....and it doesn't work :( 



    The XPath one will click only the root folders, and using FindAllChildren looks like it should work but it doesn't -  InnerChildren.ChildCount is always 0.



    This control is such a headache :(  But you've given me a headstart at least, I can at lease try to work with this and see if I can come up with something :).  Please post if you come up with something, too.
  • vex's avatar
    vex
    Contributor
    This is probably a really bad way to do this, but I had to make some modifications but the below code appears to work great!



    Do you have a better way I should go about coding this?  It does work, so I'm thrilled.  You got me on the right path, so thanks!



      Set pgRestore  = Aliases.WebBrowser.Page("*")

     

      Nodes = pgRestore.EvaluateXPath("//TD[@class='ygtvlp']//DIV[@class='ygtvspacer']")

      MidNodes = pgRestore.EvaluateXPath("//TD[@class='ygtvtp']//DIV[@class='ygtvspacer']")    

     

      While VarType(Nodes) <> varNull

        Indicator.PushText "Finding Nodes..."

        Nodes = pgRestore.EvaluateXPath("//TD[@class='ygtvlp']//DIV[@class='ygtvspacer']")

        Indicator.PushText "Finding MidNodes..."

        MidNodes = pgRestore.EvaluateXPath("//TD[@class='ygtvtp']//DIV[@class='ygtvspacer']")

        Indicator.PopText  

        If VarType(Nodes) <> varNull Then

          For i = 0 To UBound(Nodes)

            If Nodes(i).Exists = TRUE Then

              Nodes(i).Click

              Call Delay(1000)

            End If

          Next

        End If

        If VarType(MidNodes) <> varNull Then

          For j = 0 to UBound(MidNodes)

            If MidNodes(j).Exists = TRUE Then

              MidNodes(j).Click

              Call Delay(1000)

            End If

          Next

        End If              

      WEnd

  • Julia_K's avatar
    Julia_K
    SmartBear Alumni (Retired)

    Hello Vince,


    I'm glad to know that the XPath approach suits you and you were able to create working code. Good luck with your testing.


    As for the FindAllChildren issue, TestComplete may fail to access tree view items if they are generated dynamically, that is, if child nodes are generated when their parent node is expanded. Is that your case?


    Please let us know if you need any more assistance.

    Thank you.