DropdownUncachingFilter

public DropdownUncachingFilter()
{
    Require(stack => stack.Peek().UIElement.Name == "DropDown");
}

protected override void Run(IUITestActionStack stack)
{
    UITestAction action = stack.Peek();
    if (action.UIElement.Name == "DropDown")
    {
        // It's important not to throw away the existing search
        // configuration information. Unfortunately, it's also
        // not mutable inline, so we have to make a new one.
        string[] previousConfiguration = action.UIElement.QueryId.SearchConfigurations;
        string[] configuration = new string[previousConfiguration.Length + 1];
        for (int i = 0; i < previousConfiguration.Length; ++i)
        {
            configuration[i] = previousConfiguration[i];
        }
        // AlwaysSearch is the configuration that disables caching
        // of the element.
        configuration[previousConfiguration.Length] = "AlwaysSearch";
        action.UIElement.QueryId.SearchConfigurations = configuration;
    }
}

The coded UI system tries to cache its knowledge of UI elements as often as possible for performance. This can cause problems in situations where a single UI element is reused in different situations. One instance where this occurs is in the dropdown menus of the navigation toolbar. This confuses the playback system, making the navigation toolbar inconsistent. This filter fixes that by adding the "AlwaysSearch" string to the search configurations of any action on a dropdown.

Last edited Aug 1, 2014 at 7:25 PM by wgoodin, version 4