Handling dialog and pop up windows

Class library usage, coding and language questions.
omayer
Posts: 458
Joined: Thu Oct 28, 2010 6:14 pm

Handling dialog and pop up windows

Post by omayer » Fri Dec 09, 2011 3:37 am

I am trying to follow the step @ http://www.ranorex.com/blog/handling-di ... up-windows

But can't figure out where to start another thread and where does this code goes to:

Report.Info("Start simulating pop ups by pressing the 'Start' button.");
repo.AppDialogSimulator.ButtonStart.Click();

// Creates and starts a new thread
// which handles unexpected dialogs
Thread dialogWatcher = new Thread(ClosePopUpDialogs);
dialogWatcher.Start();

Report.Info("Start simulating pop ups by pressing the 'Start' button.");
repo.AppDialogSimulator.ButtonStart.Click();

// Creates and starts a new thread
// which handles unexpected dialogs
Thread dialogWatcher = new Thread(ClosePopUpDialogs);
dialogWatcher.Start();The new thread called “dialogWatcher” executes the so-called “ClosePopUpDialogs” method, which does the job of closing the dialogs once they pop up:

view plaincopy to clipboardprint
public static void ClosePopUpDialogs()
{
while (true)
{
if (repo.Dialog_01.SelfInfo.Exists() )
{
Thread.Sleep(300);
Report.Screenshot(repo.Dialog_01.Self);
repo.Dialog_01.Yes.Click();
}
if (repo.Dialog_02.SelfInfo.Exists() )
{
Thread.Sleep(300);
Report.Screenshot(repo.Dialog_02.Self);
repo.Dialog_02.Retry.Click();
}
if (repo.Dialog_03.SelfInfo.Exists() )
{
Thread.Sleep(300);
Report.Screenshot(repo.Dialog_03.Self);
repo.Dialog_03.Close.Click();
}
Thread.Sleep(1000);

// Check if the 'Start' button's enabled state is set to true
// The 'Enabled' property is used to determine whether
// the simulation has been stopped manually by the user
if (repo.AppDialogSimulator.ButtonStart.Enabled == true )
{
Report.Info("Simulation was interrupted manually");
Report.Screenshot(repo.AppDialogSimulator.Self);
break;
}
}
}
Tipu

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: Handling dialog and pop up windows

Post by Support Team » Fri Dec 09, 2011 1:17 pm

Hi,

You have to start the thread when you know that pop up windows can appear.
In the sample, pop up windows are created after the "Start" button was clicked, therefore the thread was started after the specific click, but you can also start the thread at the beginning of your test script.
As the thread works in the background it is not so important when you start the thread.
To get a better overview about the principles of threads I would suggest to take a look at the following links:
link1
link2

Regards,
Markus
Ranorex Support Team
.
Image