How to track the appearance of a MessageBox for Testing WPF app?

61 Views Asked by At

Anybody know how to test Message Box, it`s appearance? While i wrote this code:

    [TestMethod]
    public void TestDisplayError()
    {
        Application application = Application.Launch("D:\\VS projects\\2Lab\\2Lab\\bin\\Debug\\netcoreapp3.1\\2Lab.exe");
        Window window = application.GetWindows().First();
        TextBox t1 = window.Items[5] as TextBox;
        TextBox t2 = window.Items[4] as TextBox;
        List<Button> buttons = CreateButtonList(window);
        t1.Text = "5";
        t2.Text = "0";
        DevideButtonClick(buttons);

    }

The point is when i try divide by zero, message box must appearance. And i must testing it

1

There are 1 best solutions below

0
Nikolay On
    [TestMethod]
    public void TestDisplayError()
    {
        Application application = Application.Launch("D:\\VS projects\\2Lab\\2Lab\\bin\\Debug\\netcoreapp3.1\\2Lab.exe");
        Window window = application.GetWindows().First();
        Assert.IsNotNull(window);
        TextBox t1 = window.Items[5] as TextBox;
        TextBox t2 = window.Items[4] as TextBox;
        List<Button> buttons = CreateButtonList(window);
        t1.Text = "5";
        t2.Text = "0";
        DevideButtonClick(buttons);
        var messageBox = window.MessageBox("");
        Assert.IsNotNull(messageBox);

    }