我已经为一组工具栏定义了一个UI测试控件,它们出现在windows应用程序的每个屏幕上。工具栏上每个控件的搜索属性在它出现的每个屏幕上都是相同的,但有一个例外。
所以在下面的例子中...
UITestControl ControlName = AllUIMaps.ClientMaps.TopBars.Window.Screen.Toolbar_Icon.Toolbar.Button_ChangePassword..。第五个元素(Screen)接受ControlName的搜索属性,我可以为工具栏出现的每个屏幕编写一个UIMap。然而,这似乎有点过了。
有没有可能更改上面例子中第五个元素(ControlName = whateverscreenIamon)的搜索属性,这样我就可以编写一个助手,它会传递给整个UITestControl并修改.Screen元素?
发布于 2018-08-23 18:37:04
我的测试项目中有一个WpfCustom对象。该类没有任何代码来更改这些搜索属性,它继承了WPFCustom类,但我对它进行了修改,向您展示了如何在控件的新实例中传递这些搜索属性。我还没有确认这个代码是否可以工作,它更像是一个概念。我省略了null检查等,以使示例更清晰:
using Microsoft.VisualStudio.TestTools.UITesting;
using Microsoft.VisualStudio.TestTools.UITesting.WpfControls;
using System.Collections.Generic;
using System.Linq;
namespace Example
{
public class Sample : UITestControl
{
public Sample(UITestControl searchLimitContainer) :
base(searchLimitContainer)
{
#region Search Criteria
this.SearchProperties[WpfControl.PropertyNames.ClassName] = "Foo";
this.SearchProperties[WpfControl.PropertyNames.AutomationId] = "Bar";
#endregion
}
/// <summary>
/// Create a control with user defined searchproperties using a existing control from e.g. the UIMap.
/// </summary>
/// <param name="searchLimitContainer">your control.</param>
/// <param name="searchPropList">List of properties needed to find the control on your UI.</param>
public Sample(UITestControl searchLimitContainer, params KeyValuePair<PropertyExpression, string>[] searchPropList) :
base(searchLimitContainer)
{
foreach (var keyValuePairItem in searchPropList)
{
this.SearchProperties.Single(sp => sp == keyValuePairItem.Key).PropertyValue = keyValuePairItem.Value;
}
}
}
}您应该能够像这样使用它:
UITestControl ControlName = new Sample(AllUIMaps.ClientMaps.TopBars.Window.Screen, searchPropList)不确定您是否可以实际更改UIMap,它是生成的代码
https://stackoverflow.com/questions/51980024
复制相似问题