CodedUi :How to go about for search property of window when its title name keeps changing?

南笙酒味 提交于 2020-01-05 08:41:46

问题


I am trying to automate a click on control within window, and depending on what is selected within window, the tile of the window changes.Like sometime it is "abc",second time it will be "123".There is no common string in window title for two scenarios

When I recorded the coded ui test, it assumed the title as "abc". Now I want to customize the test somehow, so that any title will work.

How can I do so?

Any help will be great.


回答1:


You can change the searchProperties in runtime, like this:

myUITestControl.SearchProperties.Remove(UITestControl.PropertyNames.Name); myUITestControl.SearchProperties.Add(UITestControl.PropertyNames.Name, "123");

This should be done before the control is first searched. So maybe in the ctor of your test-class. (alternatively you can also add "AlwaysSearch" to the UITestControl's SearchConfigurtation)

Greetings Johannes




回答2:


There really aren't a lot of built in "good" options with CodedUI tests. Writing a dozen lines of search property changes for every test case is a major pain not to mention being error prone (forget to change property and the test breaks or slows to a crawl). There isn't a way to use a variable in the search properties that are set in the UIMap.designer file or at least I couldn't figure out a way that would stick after the file was regenerated. Moving everything out of the designer file isn't a good option either as controls don't seem to move with the methods they are attached to.

When I ran into the problem I ended up using reflection on the UIMap and doing a giant run time search and replace on the search properties for each control. Not an ideal solution but it does work and has saved me from writing a lot of individual search properties changes.




回答3:


you can use a declared variable

variable = "Value"; (even possible with arrays) myUITestControl.SearchProperties[UITestControl.PropertyNames.Name] = Variable; myUITestControl.SearchProperties[UITestControl.PropertyNames.Name] = Variable[1];

or if you know part of the window name you can use:

myUITestControl.SearchProperties.Add("Name", "Value", propertyExpressionOperator.Contains);

or myUITestControl.SearchProperties.Add(new PropertyExpression(WinWindow.PropertyNames.Name, "Value", PropertyExpressionOperator.Contains));



来源:https://stackoverflow.com/questions/8816671/codedui-how-to-go-about-for-search-property-of-window-when-its-title-name-keeps

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