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

Time:10-01

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

CodePudding user response:

Okey i changed my mind. Here is solution

CodePudding user response:

    [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);

    }
  • Related