PopupWatcher: Execute recording or user code if popup is found?

Ask general questions here.
mrt
Posts: 257
Joined: Mon Mar 16, 2020 11:31 am

PopupWatcher: Execute recording or user code if popup is found?

Post by mrt » Mon Aug 29, 2022 10:59 am

Dear all,

I want to make use of the PopupWatcher library from the Ranorex Automation Helpers.
It already works fine to check for a popup and confirm it with e.g. OK button.
But, in my case, I need to do additional actions when the popup shows up, so basically "if popup appears, do ...."

How is it possible to execute a user code method or a recording conditionally on the popup's appearance?

I tried something like

Code: Select all

PopupWatcher myWatcher = new PopupWatcher();
myWatcher.Watch(myRepository.AlarmPopup.SelfInfo, myUserCodeMethod);
myWatcher.Start();
but it does not build with errors like
Argument 2: cannot convert from 'method group' to 'Ranorex.PopupItemCallback' (CS1503)
I do not know what exactly a "Notification callback" is, and if this should fit what I am aiming for.

thank you in advance!
BR mrt

csaszi89
Posts: 41
Joined: Mon Jan 17, 2022 12:10 pm

Re: PopupWatcher: Execute recording or user code if popup is found?

Post by csaszi89 » Mon Aug 29, 2022 3:20 pm

Hi mrt,

the definition of PopupItemCallback delegate looks like this:

Code: Select all

public delegate void PopupItemCallback(RepoItemInfo info, Element target);
Based on this, you need to pass a method reference with the same signature as the second parameter of Watch method.
The code module looks like this:

Code: Select all

void ITestModule.Run()
{
    PopupWatcher myWatcher = new PopupWatcher();
    myWatcher.Watch(liberoMANAGERRepository.Instance.LiberoMANAGER, MyPopupItemCallbackMethod);
    myWatcher.Start();
}

private void MyPopupItemCallbackMethod(RepoItemInfo info, Element target)
{
    // callback actions here...
}
Best regards,
Gyuri

mrt
Posts: 257
Joined: Mon Mar 16, 2020 11:31 am

Re: PopupWatcher: Execute recording or user code if popup is found?

Post by mrt » Tue Aug 30, 2022 7:59 am

Ah yes, I found that out too yesterday, forgot to update forum post.

Thank you, that works!

mrt
Posts: 257
Joined: Mon Mar 16, 2020 11:31 am

Re: PopupWatcher: Execute recording or user code if popup is found?

Post by mrt » Tue Aug 30, 2022 4:19 pm

Do you know how to set a (global) parameter to some value when a popup was catched (e.g. to use this parameter in a testcase if-condition?

I can add parameters to the user code like usual, but when accessing them inside the PopupItemCallback method, I face an error
An object reference is required for the non-static field, method, or property 'CodeModules.StartPopupWatcher.myGlobalParameter.get'
thanks!

mrt
Posts: 257
Joined: Mon Mar 16, 2020 11:31 am

Re: PopupWatcher: Execute recording or user code if popup is found?

Post by mrt » Tue Jan 31, 2023 3:35 pm

Is there any way to STOP a popup watcher which was started like this?

Some line like:

Code: Select all

Ranorex.AutomationHelpers.UserCodeCollections.PopupWatcherLibrary.Watchers.Add(myWatcher);
seems to do nothing, the Watchers list has a GET method only, therefore the watchers list stays empty all the time.

So also

Code: Select all

Ranorex.AutomationHelpers.UserCodeCollections.PopupWatcherLibrary.StopAllPopupWatchers();
which loops through the watchers list does nothing on an empty list.

any idea?