Limit the search depth of Find calls

4 posts, 0 answers
  1. Andreas
    Andreas avatar
    3 posts
    Member since:
    Oct 2012

    Posted 18 Oct 2012 Link to this post

    Hi,

    searching for UI elements in the visual tree using the Find class is very common in UI tests. Calling SilverlightApp.RefreshVisualTrees or FrameworkElement.Refresh is quite expensive and slows the test execution down, but sometime unavoidable (as far as I know) to detect newly created elements, popups etc.

    In most cases, it is clear for which dialog/popup etc. I'm looking for. I know where in the visual tree it will appear. But I always have to call Refresh on the (potential) parent (or even SilverlightApp.RefreshVisualTrees), which seems to work through the entire (sub-) tree.

    I'd like to limit the search/refresh depth in theses cases. Is this possible somehow? Is it a sensible feature request?
    Some other ideas how to speed up the detection of newly created elements?

    Regards,
    Andreas
  2. Cody
    Admin
    Cody avatar
    3360 posts

    Posted 23 Oct 2012 Link to this post

    Hi,

    You are correct in that SilverlightApp.RefreshVisualTrees will rebuild Test Studio's in-memory cache copy of the Visual Tree from scratch, and yes this is a relatively expensive operation. FrameworkElement.Refresh can also be relatively expensive, but not as much.

    As an alternative, if you're looking for/waiting for a specific element to be created/appear you can use a Wait.For coded step instead like this:

    public class MySilvFinder : XamlElementContainer
    {
        public MySilvFinder(VisualFind find) :
            base(find)
        {
        }
    }
     
        MySilvFinder MyFinder = new MySilvFinder(Manager.ActiveBrowser.SilverlightApps()[0].Find);
        TextBlock MyTextProxy = MyFinder.Get<TextBlock>(new XamlFindExpression("AutomationId=sum"), false, 0);
        MyTextProxy.Wait.ForExists(60000);

    If you have trouble following the code let me know and I'll try to explain it more clearly.

    All the best,
    Cody
    the Telerik team
    Quickly become an expert in Test Studio, check out our new training sessions!
    Test Studio Trainings
  3. Andreas
    Andreas avatar
    3 posts
    Member since:
    Oct 2012

    Posted 06 Nov 2012 Link to this post

    Hi,

    we are using the strategy FindStrategy.WhenNotVisibleThrowException. Seems that your suggested approach will not work then?

    Regards,
    Andreas
  4. Cody
    Admin
    Cody avatar
    3360 posts

    Posted 06 Nov 2012 Link to this post

    Hi Andreas,

    It should still work as expected even when you have set FindStrategy.WhenNotVisibleThrowException. I'll try to explain why.

    1) The code MyFinder.Get will not throw an exception. It doesn't even find any real element. It creates a "proxy" object which can be used later to find an element.
    2) The code MyTextProxy.Wait.ForExists will only throw an exception if the element still does not exist after a 60 second timeout. It will not throw an exception before then. Instead it's monitoring the application and waiting for the target element to be present.

    Greetings,
    Cody
    the Telerik team
    Quickly become an expert in Test Studio, check out our new training sessions!
    Test Studio Trainings
Back to Top