PopupWatcher Screenshot

Class library usage, coding and language questions.
mafi
Posts: 21
Joined: Thu Mar 21, 2019 2:43 pm

PopupWatcher Screenshot

Post by mafi » Tue Oct 08, 2019 8:39 am

Hi All,
I wound need to use popupwatcher to detect error popups in my application, but I would screenshot them before click on dismiss button in order to let automatic test to continue.
I am not able to detect/take screenshot/dismiss, but only to detect/dismiss, using StartPopupWatcher method.
Does anybody know how to take screenshot anytime a popupwatcher item is detected?
Do you know any method or do you have any suggestion to achieve it?
Thank you very much in advance for your opinion.

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

Re: PopupWatcher Screenshot

Post by odklizec » Tue Oct 08, 2019 9:37 am

Hi,

I'm using a custom StartPopupWatcherAndWatch method, which is derived form StartPopupWatcher. basically, instead of clicking a popup element, it just watch an element and writes about it in report. Simply add these two methods to Automation Helpers > PopupWatcherLibrary and then call StartPopupWatcherAndWatch method in code module, where you initialize your popupwatchers:

Code: Select all

        /// <summary>
        /// Waits for a popup window to appear and write about it in report
        /// </summary>
        /// <param name="findElement">Element to wait for</param>
        /// <param name="watchMethod">Element to click after the popup appears</param>
        /// <returns>Reference to a newly created <see cref="PopupWatcher"/></returns>
        [UserCodeMethod]
        public static PopupWatcher StartPopupWatcherAndWatch(RepoItemInfo findElement)
        {
        
            var key = findElement.GetMetaInfos()["id"];

            if (watchers.ContainsKey(key))
            {
                throw new ArgumentException("Popup watcher with given parameters already exists.");
            }

            var watcher = new PopupWatcher();
            watcher.Watch(findElement, watchMethod);
            watcher.Start();
            watchers.Add(key, watcher);
            Report.Info("Popup watcher started.");
            return watcher;
        }
        
        public static void watchMethod(RepoItemInfo myInfo, Ranorex.Core.Element myElement)
        {
        	Report.Screenshot(ReportLevel.Failure, "PopupWatcher", "An error occured!",myElement.Parent.Parent, true,null);
        }
Hope this helps?
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

mafi
Posts: 21
Joined: Thu Mar 21, 2019 2:43 pm

Re: PopupWatcher Screenshot

Post by mafi » Tue Oct 08, 2019 9:47 am

Thank you for your suggestion.
Since I have also to click the "OK" button of the watched popup, do you think I can use two different popupwatcher methods together?
I mean, StartPopupWatcherAndWatch to take screenshot and StartPopupWatcher to click for dismissing the popup?

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

Re: PopupWatcher Screenshot

Post by odklizec » Tue Oct 08, 2019 9:56 am

Hi,

I would defnitely not use StartPopupWatcher and StartPopupWatcherAndWatch for the same element, because they both starts in a separate thread and it may easily happen, that the click is performed before taking the screenshot ;) You can just add click method to watchMethod called from StartPopupWatcherAndWatch. Simply right after the Report.Screenshot action, add Click method. Then you should not need to use two popupwatchers.
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

mafi
Posts: 21
Joined: Thu Mar 21, 2019 2:43 pm

Re: PopupWatcher Screenshot

Post by mafi » Tue Oct 08, 2019 10:07 am

odklizec wrote:
Tue Oct 08, 2019 9:56 am
I would defnitely not use StartPopupWatcher and StartPopupWatcherAndWatch for the same element, because they both starts in a separate thread and it may easily happen, that the click is performed before taking the screenshot ;)
Exactly...
odklizec wrote:
Tue Oct 08, 2019 9:56 am
You can just add click method to watchMethod called from StartPopupWatcherAndWatch. Simply right after the Report.Screenshot action, add Click method.
That was what I tried to do before post the question, but I didn't know how to pass the click element to callback method... :roll:
Should I find a way to identify the button starting to the passed "RepoItemInfo findElement"?

mafi
Posts: 21
Joined: Thu Mar 21, 2019 2:43 pm

Re: PopupWatcher Screenshot

Post by mafi » Tue Oct 08, 2019 10:40 am

Ok, got it, it works, thanks.
I didn't catch how to pass the click item, but I had it alreay. :)
Thank you.

Patil
Posts: 6
Joined: Mon Dec 26, 2022 12:29 pm

Re: PopupWatcher Screenshot

Post by Patil » Mon Jan 23, 2023 6:19 am

Hi,
It was very helpful.
As I'm new to the Codework, will you please share the coding to add click method to watchMethod called from StartPopupWatcherAndWatch?
Thanks