Handling dialog and pop up windows : Automation API

Handling dialog and pop up windows

Class library usage, coding and language questions.

Handling dialog and pop up windows

Postby omayer » Fri Dec 09, 2011 4: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
omayer
 
Posts: 239
Joined: Thu Oct 28, 2010 7:14 pm

Re: Handling dialog and pop up windows

Postby Support Team » Fri Dec 09, 2011 2: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
User avatar
Support Team
Site Admin
 
Posts: 4843
Joined: Fri Jul 07, 2006 5:30 pm
Location: Graz, Austria


Return to Automation API

Who is online

Users browsing this forum: No registered users and 0 guests