Popup Watcher Error and warnings

Class library usage, coding and language questions.
Mr.Papou
Posts: 6
Joined: Mon Jul 29, 2019 6:39 pm

Popup Watcher Error and warnings

Post by Mr.Papou » Wed Jul 31, 2019 7:57 pm

Hello everyone, I'm a beginner with Ranorex and with coding. I've watch a webinar series "Ranorex Champions training workshop" and in that series they teach how to create a Popup watcher usercode.

I've tried it on my side and I work great on the surface, but during the execution of the test, without ever stopping, it gives this error,:
Error in popup dialog handler.
Show/Hide Stacktrace
at Ranorex.Core.FunctionExecuteWithTimeout.TryExecute[T](Func`1 func, TimeSpan timeout)
at Ranorex.Core.FunctionExecuteWithTimeout.WithTimeout[T](Func`1 func, Nullable`1 timeout)
at Ranorex.Plugin.ZombieableExtensions.WithZombieCheck[T](IZombieable self, Func`1 function, ZombieCheckOptions options)
at Ranorex.Plugin.WpfRemoteObject.GetChildren(TreeBuildConfiguration configuration, WpfRemoteObject apparentParent)
at Ranorex.Plugin.WpfChildrenRule.Execute(GlueRuleExecutionState state)
at Ranorex.Core.ElementEngine.ApplyGlueRules(Element element, GlueRuleExecutionStateImpl state, Boolean includeRemotes)
at Ranorex.Core.ElementEngine.ApplyGlueRules(Element element, Boolean includeRemotes)
at Ranorex.Core.Element.GetChildren(CacheSession session)at Ranorex.Core.Element.get_Children()
at Ranorex.Core.RxPath.collectAllChildren(Element self, LocationStep step, IList`1 list, Boolean includeSelf, Boolean quitOnFirstGoodNode)
at Ranorex.Core.RxPath.collectAxis(LocationStep step, Axis optimizedAxis, Element self, IList`1 elements, Boolean quitOnFirstGoodNode)
at Ranorex.Core.RxPath.ApplyInternal(RxPath path, Element startElement, Duration timeout, Boolean findSingle, CacheSession& usedCacheSession, PathDiagnostics& pathDiagnostics)
at Ranorex.Core.RxPath.Apply(Element startElement, Duration timeout, Boolean findSingle, CacheSession& usedCacheSession, PathDiagnostics& pathDiagnostics)
at Ranorex.Core.Element.TryFindInternal(RxPath path, Duration timeout, Boolean findSingle, IList`1& foundElements, CacheSession& usedCacheSession, Duration& elementSearchTime, Int32& iterations)
at Ranorex.Core.Repository.RepoItemInfo.FindInternal[T](Boolean findSingle, Boolean throwException, Duration effectiveTimeoutOverride)
at Ranorex.Core.Repository.RepoItemInfo.<>c__DisplayClass75_0`1.<Find>b__0()
at Ranorex.Core.Testing.Services.NoMaintenanceModeService.HandleElementNotFound[T](Func`1 action, RepoItemInfo entry)
at Ranorex.Core.Repository.RepoItemInfo.Find[T](Boolean findSingle, Boolean throwException, Duration effectiveTimeoutOverride)
at Ranorex.PopupWatcher.<>c__DisplayClass27_0.<WatchAndClick>b__0(RepoItemInfo i, Element e)
at Ranorex.PopupWatcher.FindPopups(PopupItemCallback itemCallback, PopupPathCallback pathCallback, RxPath absPath, String itemName, RepoItemInfo optionalInfo)

And keep on repeating, for all the Popup I've setup in my user, this warning:
Warn Popup Watcher Item 'Proto_Update_LaunchRepository.AnvilHub.Warnings_Errors.Process_Already_Running.Btn_Ok' could not be found.

Can you help me found what's wrong, please.
Here's my UserCode:
using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
using System.Drawing;
using System.Threading;
using WinForms = System.Windows.Forms;

using Ranorex;
using Ranorex.Core;
using Ranorex.Core.Testing;

namespace Proto_Update_Launch
{
    /// <summary>
    /// Description of PopupWatcher.
    /// </summary>
    [TestModule("686078CB-4A41-4C3B-BBF4-8EE83609AD0F", ModuleType.UserCode, 1)]
    public class StartPopupWatcher : ITestModule
    {
        /// <summary>
        /// Constructs a new instance.
        /// </summary>
        public StartPopupWatcher()
        {
            // Do not delete - a parameterless constructor is required!
        }

        /// <summary>
        /// Performs the playback of actions in this module.
        /// </summary>
        /// <remarks>You should not call this method directly, instead pass the module
        /// instance to the <see cref="TestModuleRunner.Run(ITestModule)"/> method
        /// that will in turn invoke this method.</remarks>
        void ITestModule.Run()
        {
            Mouse.DefaultMoveTime = 300;
            Keyboard.DefaultKeyPressTime = 100;
            Delay.SpeedFactor = 1.0;
            
            var Repo = Proto_Update_LaunchRepository.Instance;
            
        //// Anvil is already running
        	PopupWatcher anvilRunningPopup = new PopupWatcher();
         	anvilRunningPopup.WatchAndClick(Repo.AnvilHub.Warnings_Errors.Process_Already_Running, 
        	                                Repo.AnvilHub.Warnings_Errors.Process_Already_Running.Btn_OkInfo);
        	anvilRunningPopup.Start();
            
		//// Cant submit with version
			PopupWatcher cantSubmitPopup = new PopupWatcher();		
          	cantSubmitPopup.WatchAndClick(Repo.AnvilEditor.Anvil_Editor.Warnings_Errors.Cant_Submit_Data, 
			                              Repo.AnvilEditor.Anvil_Editor.Warnings_Errors.Cant_Submit_Data.Btn_OKInfo);
            cantSubmitPopup.Start();
            
        //// Guildlib is already running
        	PopupWatcher guildlibRunningPopup = new PopupWatcher();
          	guildlibRunningPopup.WatchAndClick(Repo.AnvilHub.Warnings_Errors.Process_Already_Running, 
        	                                   Repo.AnvilHub.Warnings_Errors.Process_Already_Running.Btn_OkInfo);
        	guildlibRunningPopup.Start();
        	
    	//// Fire Installer Error on install
    		PopupWatcher fireErrorPopup = new PopupWatcher();
    		fireErrorPopup.WatchAndClick(Repo.Warnings_Errors.FireInstaller.FireInstallerError,
    		                             Repo.Warnings_Errors.FireInstaller.FireInstallerError.Btn_OKInfo);
    		fireErrorPopup.Start();

        }
    }
}
Thank you in advance,
Pascal

User avatar
qwertzu
Posts: 273
Joined: Wed Jan 25, 2017 11:08 am

Re: Popup Watcher Error and warnings

Post by qwertzu » Fri Aug 02, 2019 12:26 pm

Hi,

There exists an easier way to implement a popup watcher.
You can use the user code module form the Ranorex Automation Helpers.

1. add the automation helpers
2. In a Recording module choose "Add new action" -> "User Code" -> "select from library"
3. choose modules for starting and stopping a popupwatcher

regards, qwertzu

Mr.Papou
Posts: 6
Joined: Mon Jul 29, 2019 6:39 pm

Re: Popup Watcher Error and warnings

Post by Mr.Papou » Fri Aug 02, 2019 1:14 pm

Thanks, I know about the Automation Helpers :) , but I wanted to create my own user code in a learning process to improve myself.
The Popup Watcher I made is functionnal, but gives me those warnings and errors. I've tried to search for answers as why i got those, but since I found nothing, I've decide to ask here, see if someone can help me figure it out.

Mr.Papou
Posts: 6
Joined: Mon Jul 29, 2019 6:39 pm

Re: Popup Watcher Error and warnings

Post by Mr.Papou » Tue Oct 01, 2019 2:30 pm

With work and a little bit of help from my co-worker, I was able to figure out what was the problem.

If someone is looking for the solution, it's quite simple I think.

My User Code Module was built to loop and watch multiple popup at the sametime, so the warnings were just the result of that loop informing me that he was not finding each elements, one by one in a loop.

What I did was regrouping my different Popups under one RxPath and instead of running multiple watcher for each popups, I run one watcher, but my RxPath manage the different Popups.

Now my code looks like this
using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
using System.Drawing;
using System.Threading;
using WinForms = System.Windows.Forms;

using Ranorex;
using Ranorex.Core;
using Ranorex.Core.Reporting;
using Ranorex.Core.Repository;
using Ranorex.Core.Testing;

namespace Proto_Update_Launch
{
    /// <summary>
    /// This Popup Watcher will close all Benign Popups that are set in the RxPath Popups.KnownBenignPopups
    /// </summary>
    [TestModule("B4ACC921-C809-40B5-B05C-6CB98E8E78D5", ModuleType.UserCode, 1)]
    public class StartPopUpWatcher : ITestModule
    {
        public StartPopUpWatcher()
        {

        }

        /// <remarks>You should not call this method directly, instead pass the module
        /// instance to the <see cref="TestModuleRunner.Run(ITestModule)"/> method
        /// that will in turn invoke this method.</remarks>

        void ITestModule.Run()
        {
            Mouse.DefaultMoveTime = 300;
            Keyboard.DefaultKeyPressTime = 100;
            Delay.SpeedFactor = 1.0;
            
	    var Repo = Proto_Update_LaunchRepository.Instance;
			
	    PopupWatcher PopUpCheck = new PopupWatcher();
            PopUpCheck.EnableReportMessages = false;
            PopUpCheck.WatchAndClick(Repo.Popups.KnownBenignPopups.SelfInfo, 
        	                                                         Repo.Popups.KnownBenignPopups.OkButtonInfo);
            PopUpCheck.Start();           
        }
    }
}