StopPopupWatcher after failure

Best practices, code snippets for common functionality, examples, and guidelines.
HansSchl
Posts: 125
Joined: Wed Sep 19, 2018 10:05 am

StopPopupWatcher after failure

Post by HansSchl » Fri Apr 01, 2022 3:37 pm

Hi,

playing around with the PopupWatcherLibrary from RanorexAutomationHelpers. Great tool, congrats to whoever wrote it! I have one remaining question. Assume I am running a data-driven test, with dozens of data records supplied from a source, and error behaviour is set to "continue with iteration".

Within the test loop, I have a recording which calls StartPopupWatcher, then does something, then calls StopPopupWatcher. What will happen if this "something" fails? Will the popup watcher remain in limbo, or is there some automatic cleanup, or does it get cleaned up in the next iteration when StartPopupWatcher is called again with the same repository items? Or maybe it doesn't matter to leave some dangling popup watchers as long as they don't interfere with other parts of the test?

I noticed that the generated C# code of every recording contains an empty "Init" function which I could extend, but unfortunately, no corresponding "Exit" for final cleanup.

Hoping for suggestions
Hans

Jacob
Certified Professional
Certified Professional
Posts: 120
Joined: Mon Mar 22, 2021 10:01 pm

Re: StopPopupWatcher after failure

Post by Jacob » Fri Apr 01, 2022 8:01 pm

Hi Hans!

My understanding of the PopupWatcher methods is that the processes (if not stopped) will continue to run as long as the TestSuite runs, but is closed when the Test Suite completes. The good news is that part of the behavior and error handling in the StartPopupWatcher method checks to see if there is already a PopupWatcher running with the same parameters and will throw an ArugumentException (Popup watcher with given parameters already exists) and will not start a new instance of a duplicate PopupWatcher. I hope this helps!

--Jacob
Image

HansSchl
Posts: 125
Joined: Wed Sep 19, 2018 10:05 am

Re: StopPopupWatcher after failure

Post by HansSchl » Mon Apr 04, 2022 11:38 am

Hi Jacob,

So probably the best way is to call StopAllPopupWatchers before StartPopupWatcher.

What is the lifetime of a popup watcher if it isn't stopped? I understand that it is stored in the 'watchers' dictionary which is a static member of PopupWatcherLibrary, so it will probably live until the test project (testname.exe file) has finished all test suites.

I wished there were an 'Exit' function i the user code of a recording, like there is 'Init'...

Regards
Hans

Jacob
Certified Professional
Certified Professional
Posts: 120
Joined: Mon Mar 22, 2021 10:01 pm

Re: StopPopupWatcher after failure

Post by Jacob » Mon Apr 04, 2022 6:15 pm

Hi Hans,

You are correct in that the PopupWatcher is maintained until stopped or until all Test Suites are finished. The only way I'm aware of to stop an individual Popupwatcher would be to remove it from the dictionary using the StopPopupWatcher method:
        public static void StopPopupWatcher(RepoItemInfo findElement, RepoItemInfo clickElement)
        {
            CheckArgumentNotNull(findElement, "findElement");
            CheckArgumentNotNull(clickElement, "clickElement");

            var key = findElement.GetMetaInfos()["id"] + clickElement.GetMetaInfos()["id"];
            PopupWatcher watcher = null;
            if (watchers.TryGetValue(key, out watcher))
            {
                StopPopupWatcher(key, watcher);
            }
            else
            {
                Report.Warn("The popup watcher you tried to remove does not exist.");
            }
        }
You would just need to pass the corresponding elements into the method to target the specific PopupWatcher you want to stop. Otherwise, StopAllPopupWatchers is a perfectly viable option!

--Jacob
Image

User avatar
doke
Posts: 73
Joined: Fri Mar 29, 2019 2:33 pm

Re: StopPopupWatcher after failure

Post by doke » Tue Apr 12, 2022 2:49 pm

Hi Hans,

Please note that the popuphandler functionality is created for handling Unexpected popup windows!
MOST popups are not really unexpected, but often unwanted and caused by uncontrolled environment variables/circumstances
My example below (step4) is also solvable without a popup handler using a conditional step( enable continue on fail) to click ok on the popup.

You might have an real unexpected popup or you have other reasons to implement popupwatchers ( reduce run test time, easier to use conditional steps, ... )

My expierence with popupwatchers made my decide to try to stop them as soon as possible.
because:
- to many popuphandlers cost to much performance
- mistakes on "generic" popupshandlers might trigger 2 handlers at same time

example how I try to do things:
suite
  setup
     recording-startapplication
        step1-start apllication
        step2-login enter username
        step3-login enter password+enter
        step4-startpopuphandler possiblewarningafterlogin
        step5-waitfor exists screenafterlogin
        step6-stop popuphandler possiblewarningafterlogin 
  TC with iteration
     smartfolder 
        recording1 start popuphandlerX
        recording2     
        recording3 stop popuphandlerX
     teardown TC
       stopallpopupwatchers or stopallpopupwatchers used in recording1+2+3  (*)
  teardown (suite)
    stopallpopupwatchers 
if you don't have teardown with (*) and error happens in recording2 in first iteration - you might have open popupwatchers for rec1
when error handling is "continue with iteration" you go to second iteration: now an error is throw when rec1 is executed as the popup handler already exists, and all your following iterations fail.

Regards,

Don