Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I access a MessageBox with white?

I have a simple message box in a WPF application that is launched as below:

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

I can get white to click my button and launch the message box.

UISpy shows it as a child of my window I couldn't work out the method to access it.

How do I get access to my MessageBox to verify its contents?

like image 722
Brownie Avatar asked Mar 02 '23 07:03

Brownie


2 Answers

Found it! The window class has a MessageBox method that does the trick:

        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);
like image 173
Brownie Avatar answered Mar 04 '23 09:03

Brownie


Please try this

       Window messageBox = window.MessageBox("");
       var label = messageBox.Get<Label>(SearchCriteria.Indexed(0));
       Assert.AreEqual("Hello",label.Text);
like image 25
embarus Avatar answered Mar 04 '23 09:03

embarus