Programmatically find a message box and generate a click on a button

I am trying to automate winform application testing. I run it in the same process as the test code, so it’s pretty easy to find .Net controls and simulate user actions on them. However, I got a little stuck in the message box (created using the standard MessageBox.Show method). How can I grab it and simulate a button being pressed?

+3
source share
6 answers

You will probably have to use WinAPI calls (FindWindowEx, ect) and send LMB messages down and down to the button handle.

+2
source

, . ,

, - . , . , , ... - ( 2- )

public class UserInterrogator : IUserInterrogator
{
    private Form owner;

    public UserInterrogator(Form owner)
    {  this.owner = owner;    }

    public Font GetFontFromUser()  // member of the IUserInterrogator interface
    {
        FontDialog fd = new FontDialog();
        fd.ShowDialog( owner );
        return fd.Font;
    }
}

- , , , / . , API- Win32 NUnitForms...

+6
  • codeplex.com/white -

  • testautomationfx.com - ,

+3

( ), Application.OpenForms.

+2
+2

You can use autoit script.

But I propose to separate the GUI and the implementation , because the basic principle of unit testing is the β€œunit”, where the unit is a class that is separate from other classes or the real world.
This principle gives you a good class design and helps to avoid software eruptions and many other useful things.

0
source

Source: https://habr.com/ru/post/1714392/


All Articles