Forum Discussion

cruzader's avatar
cruzader
Contributor
15 years ago

How to test if a dialog is modal or modeless

Hello,



I'm currently testing a WPF application.

How can I check if a certain dialog is shown as modal or modeless?

I cannot find a property which says Modal. :-)




Thanks in advance.




Regards,

cruzader

3 Replies

  • Hi Ruel,




    There is no such a property. I suggest using the following procedure to determine whether there is a modal WPF dialog:

    1. Get the main window object.

    2. Get the window object of the dialog you want to check.

    3. Try to activate the main window.

    4. Find out whether the OnUnexpectedWindow event is raised.




    To determine whether this event has been raised, follow the steps below:

    1. Set a global project variable (see the 'Project and Project Suite Variables - Overview' help topic).

    2. Set your own handler for the OnUnexpectedWindow event. It should be like this:




        function GeneralEvents_OnUnexpectedWindow(Sender, Window, LogParams)

        {

            Project.Variables.Var1 = true;

        }




    Here is a script example. It works with the Orders.exe sample application:




    [JScript]

        function checkModal(mainWindow)

        {

            Project.Variables.Var1 = false;

            mainWindow.Activate();




            if (Project.Variables.Var1)

                Log.Message("Modal");

            else

                Log.Message("Modeless");  

        }




        function Test1()

        {

            var  orders, grid, listView;

            var  testedWnd, mainWnd;

            TestedApps.Orders.Run();

            orders = Sys.Process("Orders");

            mainWnd = orders.WPFObject("HwndSource: MainForm");

            grid = orders.WPFObject("HwndSource: MainForm").MainForm.WPFObject("gridMain");

            grid.MainMenu.WPFMenu.Click("Orders|Edit order...");

            testedWnd = orders.Window("#32770", "Warning");

            checkModal(mainWnd);

            TestedApps.CloseAll();

        }




  • Thanks for info.

    It actually worked with my scripts.



    Additional question related to this...

    When executing this code, an item is placed in the log of TestComplete

    and it is treated as an error (with error icon).  Is there a way not

    to included it in the log of TestComplete so that the test will not be

    treated as Failed?



    Thanks again!

  • Hi Ruel,





    Use the modified event handler below:





        function GeneralEvents_OnUnexpectedWindow(Sender, Window, LogParams)

        {

            LogParams.Locked = true;

            Project.Variables.Var1 = true;

        }






    See the 'LogParams Object' help topic for more information.