Finding a window when only part of the window title is known in Coded UI Tests

让人想犯罪 __ 提交于 2019-12-12 10:58:30

问题


The application I am writing coded UI tests for has a window where part of the window title is based on a random filename generated for a temporary file, so the test can only know the static part of the window title.

Occasionally, when no other windows are open, the test runs fine. It is a bit problematic when other windows are open, however. If the other windows have similar controls, which window the test picks to work in is unpredictable.


回答1:


I've narrowed it down to this: When searching for a control, the Coded UI Test uses search properties and a tree-like structure of controls. If it can't find an exact match it finds a close match (so it can't find the exact window title name, it excludes that and keeps searching for a window that matches any other given properties) which is why it works with controls in other windows.

The solution is really to give it more search properties to work with. One method I use is to add a property using a PropertyExpression and pass it PropertyExpressionOperator.Contains.

As an example, I recorded opening MS Word and closing it. This generates a control in the UIMap, and in its constructor is the following:

this.SearchProperties[WinWindow.PropertyNames.Name] = "Document1 - Microsoft Word";
this.SearchProperties[WinWindow.PropertyNames.ClassName] = "OpusApp";

Rather, the first line should be:

this.SearchProperties.Add(new PropertyExpression(WinWindow.PropertyNames.Name, "Microsoft Word", PropertyExpressionOperator.Contains));



回答2:


Or even easier, you can use:

this.SearchProperties.Add(WinWindow.PropertyNames.Name, "Microsoft Word", PropertyExpressionOperator.Contains);


来源:https://stackoverflow.com/questions/11086713/finding-a-window-when-only-part-of-the-window-title-is-known-in-coded-ui-tests

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!