编码的UI测试:WaitForControlEnabled抛出NullReferenceException

时间:2017-03-29 10:16:28

标签: c# visual-studio-2013 coded-ui-tests

我正在为Windows应用程序编写测试,并尝试等待按钮启用时。

var mainWindow = new WinWindow();
mainWindow.SearchProperties[WinControl.PropertyNames.ControlName] = "mainWindow";
mainWindow.SearchConfigurations.Add(SearchConfiguration.AlwaysSearch);
mainWindow.SetFocus();

//toolbar with needed button
var toolbar = new WinToolBar(mainWindow);
toolbar.SearchProperties[UITestControl.PropertyNames.Name] = "toolbarName";

var button = new WinButton(toolbar);           
button.SearchProperties[UITestControl.PropertyNames.Name] = "buttonName";
button.DrawHighlight();
button.WaitForControlEnabled();

因此,按钮已禁用但存在。 button.DrawHighlight()正常工作,并在按钮周围绘制边框。

但是button.WaitForControlEnabled()会在没有等待超时的情况下抛出NullReferenceException: Object reference not set to an instance of an object

如果我正在使用button.WaitForControlReady(),它会抛出同样的异常而不等待超时,即使按钮存在并启用。

我做错了什么?

1 个答案:

答案 0 :(得分:1)

您的代码似乎已正确编写。如果DrawHighlight正在使用控件然后实例化它。可能是您的Visual Studio Coded UI版本存在问题。如果您正在等待单击按钮,请尝试这样的操作。希望这对你有用。

button.WaitForControlPropertyEqual(button.Enabled.ToString(), true);
相关问题