How to add custom PopupWatcher.

Ask general questions here.
User avatar
felixk91
Posts: 20
Joined: Wed Feb 10, 2016 11:16 pm

How to add custom PopupWatcher.

Post by felixk91 » Mon Mar 30, 2020 10:37 am

Hi everyone,

I would like to add custom PopupWatcher to handle the dialog that can possibly come up during test run.
I added Ranorex Automation Helpers that contains the PopupWatcher Library , but this set of methods does not contain one that can provide me with function call back, something like public static PopupWatcher StartPopupWatcher(RepoItemInfo findElement, MyCallBackMethod), where I can add some custom code for steps within call back method. I need not only close popup dialog but also perform a few steps as result of this dialog appearance.
Can someone help me with how I can add such method.
Where I should initialize PopupWhatcher? How I should add it to recording module?
If some one got an example of such kind of PopupWatcher and can share with me it will be much appreciated.

Thanks,
Felix

User avatar
N612
Posts: 135
Joined: Mon Jul 11, 2016 4:01 pm

Re: How to add custom PopupWatcher.

Post by N612 » Tue Mar 31, 2020 9:27 pm

There are some great code examples in the user guide to help you get started with this (see: "Handling unexpected dialogs
") - https://www.ranorex.com/help/latest/han ... -examples/. This should be initialized and started before the popup can exists. Generally this is the in a [SETUP] region of the test suite, but really can be anywhere you see fit.

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(); 
}

User avatar
felixk91
Posts: 20
Joined: Wed Feb 10, 2016 11:16 pm

Re: How to add custom PopupWatcher.

Post by felixk91 » Wed Apr 01, 2020 2:27 am

Hi N612,

Thanks for replying me.
Yes, I read this example, But I can't get how call back method gets element to click on.
I have to analyse if button enabled or disabled within dialog and then perform same steps.

Thanks,
Felix.

User avatar
felixk91
Posts: 20
Joined: Wed Feb 10, 2016 11:16 pm

Re: How to add custom PopupWatcher.

Post by felixk91 » Wed Apr 01, 2020 8:51 am

Thanks everyone.

I found solution.