none
Performance issue on FindFirst() and FindAll() calls of System.Windows.Automation ,while finding the child from on Win32Tree .Is there any way to optimize the calls.? RRS feed

  • Question

  • We are using some feature from System.Windows.Automation with TestStack/White .
    We are facing below performance issue on FindFirst() call.

    I am using the below code to fetch the tree node
    AutomationElement parentNode = win32TreeNode.AutomationElement.GetUpdatedCache(CacheRequest.Current);AutomationElement childNode = null;
    childNode = parentNode.FindFirst(TreeScope.Children, new PropertyCondition(AutomationElement.NameProperty, childNodeId));

    This code taking more time to fetch the node .Since the node is created dynamically from application we need to call this code again and again(re-try) to get updated value.
    Is there any suggestion to speed up this process.
    Also if we need to get the updated value second time whether we need to call FindFirst() again ?Or is there any other way we can get the updated node?
    Please provide sample snippet if possible.

    Monday, October 17, 2016 2:19 PM

All replies

  • We are using some feature from System.Windows.Automation with TestStack/White .
    We are facing below performance issue on FindFirst() call.

    I am using the below code to fetch the tree node
    AutomationElement parentNode = win32TreeNode.AutomationElement.GetUpdatedCache(CacheRequest.Current);AutomationElement childNode = null;
    childNode = parentNode.FindFirst(TreeScope.Children, new PropertyCondition(AutomationElement.NameProperty, childNodeId));

    This code taking more time to fetch the node .Since the node is created dynamically from application we need to call this code again and again(re-try) to get updated value.
    Is there any suggestion to speed up this process.
    Also if we need to get the updated value second time whether we need to call FindFirst() again ?Or is there any other way we can get the updated node?
    Please provide sample snippet if possible.

    • Merged by Oscar_Wu Monday, October 31, 2016 10:19 AM the same issue
    Monday, October 17, 2016 2:45 PM
  • Hi Sumesh_M,

    >>Since the node is created dynamically from application we need to call this code again and again(re-try) to get updated value.
    Is there any suggestion to speed up this process.

    Searches from AutomationElement.RootElement and with TreeScope.Descendants can be extremely slow. You should use a closer element, define TreeScope.Children. This will significantly speed up your performance. But based on your code, I see you have already use Children instead.

    In addition, note that if you're querying the AutomationElements themselves multiple times, you will benefit from caching the element on your first request, and always access its cached properties. You may only try this way.

    Best regards,

    Kristin


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Tuesday, October 18, 2016 2:55 AM
  • Yes Since because TreeScope.Descendants  is very slow, We are using TreeScope.Children only.Not finding any way to optimize since FindFirst() and FindAll() are feature's from System.Windows.Automation.

    Is there any other setting which will improve the performance of tree search?

    Regarding Caching ,

    if the node is updated with some properties like Node name ,Node id and all.Then cached items will auto update with new property values? Or we need to fetch again based on criteria ? In our application more frequently the node updated with new property values.

    Tuesday, October 18, 2016 4:07 AM
  • Hi Sumesh_M,

    You have posted a same thread in this forum.

    Please share me which type project you cared, Coded UI Test or others?

    Sincerely,

    Oscar


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com

    Tuesday, October 18, 2016 7:20 AM
  • Hi Sumesh_M,

    >>Since the node is created dynamically from application we need to call this code again and again(re-try) to get updated value.

    Sorry, maybe I misunderstand you. I want to make clearer than before. What do you mean by create node dynamically? For example, a window with a button create dynamically, all controls already loaded before window loaded. Or a button loaded then create another control in button click event dynamically. So I am curious about what your real scenario is.

    Could you give me a simplified sample to OneDrive if possible? I will do a further test.

    Best regards,

    Kristin 


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.



    • Edited by Kristin Xie Wednesday, October 19, 2016 1:25 AM
    Wednesday, October 19, 2016 1:19 AM
  • Hi Sumesh_M

    I've searched more, You can try other approach to get the Element. Please walk through following MSDN tutorial

    https://msdn.microsoft.com/en-us/library/ms752331(v=vs.110).aspx

    In section: Other ways to retrieve an Element, there're instructions on that.

    If the performance issue still unacceptable, also there're other automation technical for you to have a try.

     https://blogs.msdn.microsoft.com/lixiong/2009/12/05/ui-automation-under-the-hood/

    Best regards,

    Kristin


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    • Proposed as answer by Kristin Xie Monday, October 24, 2016 8:23 AM
    Wednesday, October 19, 2016 1:53 AM
  • The Tree loaded with some tree nodes which is coming from SharePoint and local cache SQLite db.

    But in actual application screen we have a button ,once we  click that it will create one new node with some information which we provide through one textbox. So based on that it will create a new node with several properties and add to existing tree.

    So in automation we create node by clicking button and we try to fetch new node from tree to validate Node creation is success or not.

    Some place retry needed to fetch the new node since there is slight delay to get new node in tree.

    So in this case we are using below code

    AutomationElement parentNode = win32TreeNode.AutomationElement.GetUpdatedCache(CacheRequest.Current);AutomationElement childNode = null;
    childNode = parentNode.FindFirst(TreeScope.Children, new PropertyCondition(AutomationElement.NameProperty, childNodeId))

    Monday, October 24, 2016 9:36 AM
  • Hi Sumesh_M,

    Sorry for my late reply.

    >>The Tree loaded with some tree nodes which is coming from SharePoint and local cache SQLite db.

    As far as I know, Windows provides a new Accessibility API called Microsoft UI Automation. This API allows programmatic access to most user interface elements on the desktop, addressing the needs of assistive technology products and also for UI test automation. But based on your description, SharePoint is web project. Using Windows.Automation has become an indirect level. thereby greatly reducing the efficiency.

    In a word, I would suggest you try to find if there is any other test tool or API to suit your scenarios.

    Best regards,

    Kristin


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.


    • Edited by Kristin Xie Friday, October 28, 2016 5:56 AM
    Friday, October 28, 2016 5:55 AM