如何访问带有白色的MessageBox?

时间:2020-03-06 14:49:29  来源:igfitidea点击:

我在WPF应用程序中有一个简单的消息框,如下所示:

private void Button_Click(object sender, RoutedEventArgs e)
{
   MessageBox.Show("Howdy", "Howdy");
}

我可以变白以单击我的按钮并启动消息框。

UISpy将其显示为我的窗口的子级,我无法确定访问它的方法。

如何访问我的MessageBox以验证其内容?

解决方案

找到了! window类具有一个可以完成此操作的MessageBox方法:

var app = Application.Launch(@"c:\ApplicationPath.exe");
        var window = app.GetWindow("Window1");
        var helloButton = window.Get<Button>("Hello");
        Assert.IsNotNull(helloButton);
        helloButton.Click();
        var messageBox = window.MessageBox("Howdy");
        Assert.IsNotNull(messageBox);