Forum Discussion

endorium's avatar
endorium
Frequent Contributor
7 years ago

Adding a delay when selecting a treeview node

I have a test that needs to select a treeview node.

It works fine but cetain nodes (networks for instance) take a while to expand and open on the first time they are used.

How can I introduce a wait so the test does not fail.

 

It would need to click the first 'x' amount of nodes, then wait while the network one expands after it has been selected.

 

Any way to do this?

  • shankar_r's avatar
    shankar_r
    Community Hero

    Tree View object has a property called Expended/wExpended  using this you can do like below,

    if(Aliases.App.win_MainWindow.treeView.WaitProperty("Expended or wExpended",true,10000)){
                Log.Message("Tree view loaded");
           }

     

    • AlexKaras's avatar
      AlexKaras
      Champion Level 3

      Hi,

       

      Another possible approach is to find something that indicates wheter or not yet the given node is expanded. E.g. .ChildCount > 0, SomeChildItem.Exists, etc.

      Then, after the node is commanded to expand, wait in a loop (within some reasonable timeout) until the condition that indicates successful expansion is met.

       

    • endorium's avatar
      endorium
      Frequent Contributor

      Thanks for the reply.

      So I have the below:

       

      "treeViewAlias.ExpandItem(folderPath, 30000);
        treeViewAlias.ClickItem(folderPath)
        Log["Message"]("Folder " + folderPath + " was selected.");"

       

      But it does not wait 30 seconds for it to expand and instead fails. The issue is that it can expand Desktop straight away. Its expanding Network that takes time. Instead of waiting for it then expanding it, it just fails as it cannot see pc11111 until network is expanded.

       

      |Desktop|Network|PC111111|LIS Folders|Lis_Import

       

      • AlexKaras's avatar
        AlexKaras
        Champion Level 3

        Hi,

         

        Generic .ExpandItem() method has no idea what to wait for in this or that case and what are the criteria that must be met to consider an item to be (successfully) expanded.

        Thus, instead of expanding the sequence of items, you should expand them one by one and wait until every given item is expanded. (Consider this extension of your sample: What test code must do if you try to expand the Network item with no network connection available? Extension 2: What to do if pc11111 is turned off?)

         

        P.S. Considering your example: unless visual selection in the tree is the only possible method to select the needed folder and unless you are testing this given treeview, it is usually more reliable and performant to provide the path (e.g. \\PC111111\LIS Folders\Lis_Import) then to select the path visually.