我正在尝试访问UI测试框架(MS UI测试(中的本机Wpf控件属性。我的具体问题是,当我尝试使用调用 WpfButtonObject.GetProperty("IsVisible"(的函数访问 WpfButton 控件属性(例如 IsVisible(时,会发生异常"System.NotSupportedExceptions"。我能够使用 Snoop 查看此 WpfButton 属性;所以,我想知道 GetProperty 调用是否正确?请参阅下面的相关代码。感谢您的任何见解。
UIMap.cs:按下 WpfButton 的测试功能。请注意调用uIButton.GetPropery("IsVisible"(。这是发生异常的地方:
public void PressButtonTest()
{
WpfButton uIButton = this.UIMainWindowWindow.UIButtonButton;
object state = uIButton.GetProperty("IsVisible"); // Throws SystemNotSupportedException exception
bool stateBool = (bool)state;
Assert.IsTrue(stateBool, "Button is visible");
PressButton();
}
UIMap.Designer.cs: WpfButton 属性:
public WpfButton UIButtonButton
{
get
{
if ((this.mUIButtonButton == null))
{
this.mUIButtonButton = new WpfButton(this);
#region Search Criteria
this.mUIButtonButton.SearchProperties[WpfButton.PropertyNames.AutomationId] = "button";
this.mUIButtonButton.WindowTitles.Add("MainWindow");
#endregion
}
return this.mUIButtonButton;
}
}
这是我所做的:
Point point;
bool isClickable = uIButton.TryGetClickablePoint(out point);
Assert.IsTrue(isClickable, "No clickable point was found, button not visible.");
顺便说一下,您在断言(第二个参数(中的消息是不准确的,因为它仅用于失败...在您的情况下,当按钮不可见时。因此,在您的输出中,它会在失败时说"按钮可见",而实际上并非如此。