Muhammad Omar Farooq
Muhammad Omar Farooq

Reputation: 131

how do we check whether a particular modal window opens or not using teststack.white Automation framework?

I am having an issue relating to modal window.

Inside the application that i am automating, a modal window opens if the user has some data but if it has not then it will not open. how can we put an "if statement" e.g, if modal window exist then do some work else skip. because i am having an error at this statement

Window childWindow = mainWindow.ModalWindow("child");

it is throwing an exception because it could not search for window with name "child". and i know that it does not exist. it should skip it if it does not exist.

Upvotes: 3

Views: 4714

Answers (2)

Taras Kozubski
Taras Kozubski

Reputation: 1874

My working code (AutomationUI):

using System.Windows.Automation;

Automation.AddAutomationEventHandler(
            WindowPattern.WindowOpenedEvent,
            mainWindow.AutomationElement,
            TreeScope.Descendants,
            (sender, e) =>
            {
                var element = sender as AutomationElement;
                if (!(element.Current.LocalizedControlType == "Dialog" && element.Current.Name == "modalWindowTitle"))
                    return;

                Automation.RemoveAllEventHandlers();
                // Here run your code. The modal window was opened
            });

Upvotes: 0

Rik
Rik

Reputation: 3887

You can try to se if there are any modal windows before executiong the ModalWindow Method

Window childWindow = null;
if(mainWindow.ModalWindows().Any())
{
    childWindow = mainWindow.ModalWindow("child");
}

else you can try to define criteria, or while for a certain timeout

...
var timer = new StopWatch();
timer.Start();
Window childWindow = null;
do 
{
    childWindow = mainWindow.ModalWindow("child");
} while (childWindow != null || timer.ElapsedMilliseconds < timeOutInMs);
...

Hope it helps.

Rik

Upvotes: 4

Related Questions