Question

I use Coded UI in VS2012. I would like to solve an interesting problem. For example, there is an application which has got a window and it has got a title with dynamic content. I would like to search this window via it's title. The next titles are the possible cases:

"AAAAAAAA This is a window title ASDASDASD or"
"BBBBBBBB This is a window title WSDWSDWSD or not"
"CCCCCCCC This is a window title ASDASDASD or"
"........ This is a window title ASDASDASD"

I would like to search something which contains "This is a window" and "or not". If i could use regex, i use the following expression to find this title: *This is a window*or not*.

I emphasize, that is only an example. The essential is there is a title which contains some fix strings.

I know, that a UITestControl has PropertyExpressionCollection which name is SearchProperties. I can add to it a PropertyExpression(propertyName, propertyValue, conditionOperator) object. The problem is: i can decide the SearchProperties with two step (formally):

WinWindow.SearchProperties.Add(WinWindow.PropertyNames.Name,"This is a window", PropertyExpressionOperator.Contains);
WinWindow.SearchProperties.Add(WinWindow.PropertyNames.Name,"or not", PropertyExpressionOperator.Contains);

How can i do it in one simple step? Or which solution can implement this requirements?

Thanks in advance, Peter

Was it helpful?

Solution

For reasons mentioned above it seems the best solution is to iterate thru all the windows under the desktop. Here's a snippet (for testing I'm looking for a notepad window) I'm not too proud of, but works and finishes under one second:

UITestControl result = null;
var TM = Playback.GetCoreTechnologyManager("MSAA");
var desktop = UITestControl.Desktop.GetChildren()[1].GetProperty(UITestControl.PropertyNames.UITechnologyElement) as UITechnologyElement;
var windowEnumerator = TM.GetChildren(desktop, null);
windowEnumerator.Reset();
while (windowEnumerator.MoveNext())
{
    UITechnologyElement current = windowEnumerator.Current as UITechnologyElement;
    if (current.Name != null &&
        current.Name.Contains("Notepad") &&
        current.Name.Contains("Untitled"))
        {
            result = UITestControlFactory.FromNativeElement(current.NativeElement, "MSAA");
            break;
        }
    }
}

I used the MSAA technology manager because it was about seven times faster than using the UITestControls. Going down to MSAA level (IAccessible) can finish the job in about 50 milliseconds but using WinApi functions may get you the same results.

I'm sorry, I can't think of any simpler solution for this problem at the moment.

OTHER TIPS

There are couple of ways to do it, 1. If you know how the Title of the page is dynamically generated, create a static variable/class and generate the title at run time and use your code.

  1. If you are aware of the possible Title's, create a static class and hardcode the values there.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top