Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to validate a messagebox popup in c#?

I was writing some tests and try to validate that some system messagebox is popping up. Like in http://www.dotnetperls.com/messagebox-show. However, the class MessageBox is for creating the messagebox. How shall I capture and validate an system generated one and operate on it?

eg: The actions are:

    1.click on some execute file.
    2.validate a warning messagebox pop up
    3.click on yes/no on the messagebox

Any hint please?

like image 541
Qingshan Zhang Avatar asked Jan 25 '26 09:01

Qingshan Zhang


1 Answers

One choice is to use White automation framework.

For example:

Window messageBox = WindowFactory.Desktop
                                 .DesktopWindows()
                                 .Find(w => w.Title.Contains("MessageBoxTitle"));
Button ok = messageBox.Get<Button>(SearchCriteria.ByText("OK"));
ok.Click();
like image 76
drets Avatar answered Jan 27 '26 00:01

drets