Pop Up Handler/Watcher

Ask general questions here.
tejas.deshpande
Posts: 32
Joined: Fri May 20, 2016 9:43 am

Pop Up Handler/Watcher

Post by tejas.deshpande » Thu Jun 09, 2016 11:37 am

Reading through the articles on the forum and the documentation I came across 2 code samples to implement the Pop Up Handler.

Sample 1 - From Documentation

Code: Select all

void ITestModule.Run()
{

 // Create PopupWatcher
 PopupWatcher myPopupWatcher = new PopupWatcher();
 
 // Add a Watch using a RanoreXPath and triggering the Method CloseUpdateCheckDialog
 myPopupWatcher.Watch("/form[@controlname='UpdateCheckForm']/button[@controlname='m_btnClose']", CloseUpdateCheckDialog);

 // Add a Watch using the info object of a button and triggering the Method CloseUpdateCheckDialog
 // myPopupWatcher.Watch(repo.UpdateCheckDialog.btCloseInfo, CloseUpdateCheckDialog);
 
 // Add a Watch using the info object of the dialog and the info object of the button to click
 // myPopupWatcher.WatchAndClick(repo.UpdateCheckDialog.SelfInfo, repo.UpdateCheckDialog.btCloseInfo);
 
 // Add a Watch using a repository folder object and the info object of the button to click
 // myPopupWatcher.WatchAndClick(repo.UpdateCheckDialog, repo.UpdateCheckDialog.btCloseInfo);

 // Start PopupWatcher
 myPopupWatcher.Start();

}

public static void CloseUpdateCheckDialog(Ranorex.Core.Repository.RepoItemInfo myInfo, Ranorex.Core.Element myElement)
{
 myElement.As<Ranorex.Button>().Click();
}

public static void CloseUpdateCheckDialog(Ranorex.Core.RxPath myPath, Ranorex.Core.Element myElement)
{
 myElement.As<Ranorex.Button>().Click();
}
I feel this code could be missing some parts.

Code Sample 2 - From http://www.ranorex.com/blog/handling-di ... p-windows/
This sample is also referred in post http://www.ranorex.com/forum/handling-d ... t2882.html

Code: Select all

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; 
} 
} 
}
Q1. Which one of the above is correct?

Sample 1 is simplistic but lacks clarity regarding background functioning and multithreading.

Sample 2 is comprehensive but difficult to configure.
The samples available on other posts use code sample 2.Hence I am attempting to use sample 2 but am not able to make it work.

Q2. Can anyone explain the location of where this code goes?
Possibly with a sample Program.cs file or its screenshot, to clarify the structure of the file.

P.S. I'm not using the default dialog or buttons shown in the code :wink:. I have "Track"ed the required dialog box and buttons in Ranorex.

I am using the popup watcher to handle the "Crash" dialog on windows to click on the "Close Program" button as shown in the screenshot below.
Crash Dialog.PNG
Crash Dialog.PNG (5.63 KiB) Viewed 2457 times
Any help is much appreciated.
Thanks.

User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 3945
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

Re: Pop Up Handler/Watcher

Post by odklizec » Thu Jun 09, 2016 11:58 am

Hi,

The first one is the actual implementation of popup watcher, applicable in Ranorex 5.x and 6.x. The second one is obsolete one, which apply to Ranorex 4.x and older.

As for where to put he code, you can use it directly in Program.cs. Eventually, you can create a new code module, where you can put it. But then you have to add the code module somewhere in your test solution (e.g. setup section of test suite), to start the popup watcher code.

Sadly, the major downside of the popup watcher is its inability to pause the main thread, from which the popup watcher is started. In other words, popup watcher can do things on background of actually running test, like clicking buttons in unexpected dialogs (to dismiss them). However, the main test thread will not stop/pause during execution of popup watcher triggered method, nor there is a way to pause it from popup watcher code. I guess it would require complete overwrite of popup watcher to allow pausing main thread?
Pavel Kudrys
Ranorex explorer at Descartes Systems

Please add these details to your questions:
  • Ranorex Snapshot. Learn how to create one >here<
  • Ranorex xPath of problematic element(s)
  • Ranorex version
  • OS version
  • HW configuration

tejas.deshpande
Posts: 32
Joined: Fri May 20, 2016 9:43 am

Re: Pop Up Handler/Watcher

Post by tejas.deshpande » Thu Jun 09, 2016 2:02 pm

Thanks odklizec.

I am new to coding. Could you please share a screenshot or sample of the Program.cs file.

I am quite confused about its structure.

Thanks.

User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 3945
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

Re: Pop Up Handler/Watcher

Post by odklizec » Fri Jun 10, 2016 7:17 am

Hi, you can implement it like this:
program.png
program.png (49.15 KiB) Viewed 2434 times
Pavel Kudrys
Ranorex explorer at Descartes Systems

Please add these details to your questions:
  • Ranorex Snapshot. Learn how to create one >here<
  • Ranorex xPath of problematic element(s)
  • Ranorex version
  • OS version
  • HW configuration

tejas.deshpande
Posts: 32
Joined: Fri May 20, 2016 9:43 am

Re: Pop Up Handler/Watcher

Post by tejas.deshpande » Tue Jun 21, 2016 11:36 am

Thanks Pavel.

I am not able to find CodeModules.Common in my program.
Program.PNG
Program.PNG (8.08 KiB) Viewed 2413 times
Is it necessary?

User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 3945
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

Re: Pop Up Handler/Watcher

Post by odklizec » Tue Jun 21, 2016 11:44 am

Hi,

CodeModules.Common is related to my project. You can ignore it. My screenshot is just an example of implementation, not something you should use 1:1 ;)
Pavel Kudrys
Ranorex explorer at Descartes Systems

Please add these details to your questions:
  • Ranorex Snapshot. Learn how to create one >here<
  • Ranorex xPath of problematic element(s)
  • Ranorex version
  • OS version
  • HW configuration

tejas.deshpande
Posts: 32
Joined: Fri May 20, 2016 9:43 am

Re: Pop Up Handler/Watcher

Post by tejas.deshpande » Tue Jun 21, 2016 12:05 pm

That's a relief!

I'm trying to click the "Close Program" button that appears when an application under test crashes.

Here's my Program.cs file:
Program-cs.png
Program-cs.png (35.66 KiB) Viewed 2409 times
Any idea what I'm doing wrong?

Update: The Pop Up Dialog can be found, but the button is not getting clicked.

User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 3945
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

Re: Pop Up Handler/Watcher

Post by odklizec » Tue Jun 21, 2016 1:21 pm

Hi,

You can try to split the Click action into MoveTo and Click, with small delay between both actions...

Code: Select all

repo.CrashDialog.CloseProgram.MoveTo();
Delay.Duration(100);
repo.CrashDialog.CloseProgram.Click();
Eventually, try to use PerformClick method, which performs click without moving mouse...

Code: Select all

repo.CrashDialog.CloseProgram.PerformClick();
You should use this method with caution, because it clicks the element without triggering any mouse click-related events, like OnMouseClick. But it may not be a problem in case of simple message box ;)
Pavel Kudrys
Ranorex explorer at Descartes Systems

Please add these details to your questions:
  • Ranorex Snapshot. Learn how to create one >here<
  • Ranorex xPath of problematic element(s)
  • Ranorex version
  • OS version
  • HW configuration