How to use MessageBoxTester?

  • aye9999

    aye9999 - 2004-07-08

    I downloaded v1.2 a few days ago. The MouseController works great, but I am having difficulty using the MessageBoxTester. I have a form that pops up a messageBox in a button's mouseDown event handler, and I try to call the MessageBoxTester class ClickOk method to dismiss the MessageBox. However, the MessageBox doesn't go away. Here is my code:

        MessageBoxTester tester = new MessageBoxTester("");

    Anything wrong here? Do you have an example that shows how to use the MessageBoxTester?

    • Luke Maxon

      Luke Maxon - 2004-07-08

      There are example tests for everything distributed with the source code.  The latest version is 1.3. 

      Here is the modified example of testing with a message box from the unit tests.

          public void TestMessageBoxOK()
            ExpectModal( "caption", "MessageBoxOkHandler" );
            MessageBox.Show( "test string", "caption" );

          public void MessageBoxOkHandler()
            MessageBoxTester tester= new MessageBoxTester( "caption" );

      The important thing to notice is that there are two methods.  The test method calls ExpectModal and gives the name of the other method that will handle the modal when it appears.

      If the modal never appears, the test will fail.  If a different modal appears, the test will fail.  (This assumes you are using one of the base classes for your test fixtures..)

      Hope this helps...

      • Jayyusi abdo

        Jayyusi abdo - 2008-06-17


        How should this Method look, make it work with DevExpress MessageBox "XtraMessageBox"?
        This Method of NUnitforms (in MessageBoxTester) did not work with DevExpress MessageBox: IntPtr FindMessageBox().

        Exactly this Methods:
        Win32.GetClassName(handle, className, 255);
        Win32.GetWindowText(handle, buffer, 255);

        ExpectModal also did not work with DevExpress MessageBox, but i used Thread zo catch the MessageBox:

                public void run()
                    while (text != "Do you really want to delete the selected element(s)?")
                            MessageBoxTester ConfirmModal = new MessageBoxTester("Confirm deletion");
                            text = ConfirmModal.Text;
                        catch (Exception)

    • aye9999

      aye9999 - 2004-07-09

      I am using NUnitForms in a system integration test, so I am not using the NUnit framwork. The NUnitForms code does not have much coupling to the NUnit framwork, it mainly uses reflection and Win32, all I have to do is to remove the Assertion code.
      So my real question was: how to send a Click event to a MessageBox popped up by a form without involving the NUnit framwork. I found a work around by sending a Key event with the Enter key as the argument. This works fine if the MessageBox only has the "Ok" button, but will not work if it has both "Ok" and "Cancel" and the focus is in "Ok" when I want to click on "Cancel".
      I'll look into the ExpectModal method. Thanks.

      • Luke Maxon

        Luke Maxon - 2004-07-09

        The expect modal method is the only supported way to do it using NUnitForms.  You can probably find a way to do it without NUnitForms, but I don't know the details. 

        Are you using another unit testing framework that you would like supported?  NUnit is the most popular.  (from what I can tell by download stats)


Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

JavaScript is required for this form.

No, thanks