This is a migrated thread and some comments may be shown as answers.

Limit the search depth of Find calls

3 Answers 33 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Andreas
Top achievements
Rank 1
Andreas asked on 18 Oct 2012, 01:24 PM
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

3 Answers, 1 is accepted

Sort by
0
Cody
Telerik team
answered on 23 Oct 2012, 09:27 PM
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
0
Andreas
Top achievements
Rank 1
answered on 06 Nov 2012, 10:26 AM
Hi,

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

Regards,
Andreas
0
Cody
Telerik team
answered on 06 Nov 2012, 06:45 PM
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
Tags
General Discussions
Asked by
Andreas
Top achievements
Rank 1
Answers by
Cody
Telerik team
Andreas
Top achievements
Rank 1
Share this question
or