Report failure with PopupWatcher

Class library usage, coding and language questions.
kmck
Certified Professional
Certified Professional
Posts: 83
Joined: Fri Jul 12, 2013 2:41 pm

Report failure with PopupWatcher

Post by kmck » Mon Jan 20, 2014 5:44 pm

I am using a popupwatcher in Program.cs to look for an unexpected dialogue that can occur occasionally with my AUT, however rather than handling the popup and going on its way, I would like for it to throw a failure in the test so I can know where the popup occurred.

Is this possible?

I noticed in the below listed thread Markus mentions watching for a specified item and then calling a method, but I'm confused how to get this to function correctly. Has anyone else implemented something similar successfully?

http://www.ranorex.com/forum/how-to-cus ... t5037.html

mebner

Re: Report failure with PopupWatcher

Post by mebner » Wed Jan 22, 2014 12:33 pm

Hi,

Do you want to end the test, or do you want to log a failure when the pop up occurs?
If you want to log a failure, you just need to use the "Report.Failure("Your Message");" method, in the popup watcher's method.
If you want stop the test, you can follow the approach described here: How to detect error icon coming from web application..

Regards,
Markus

kmck
Certified Professional
Certified Professional
Posts: 83
Joined: Fri Jul 12, 2013 2:41 pm

Re: Report failure with PopupWatcher

Post by kmck » Wed Jan 22, 2014 1:54 pm

Hi Markus,

Thanks for responding. Correct, I am only looking to log a failure once the popup appears, but not end the test suite. I think I am a little unclear as to how to set the report category to failure within the PopupWatcher method, could you please provide an example?

Thank you.

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

Re: Report failure with PopupWatcher

Post by odklizec » Wed Jan 22, 2014 4:16 pm

Hi,

I'm using PopupWatcher to save a screenshot of popup window just before its closure.

This code goes to Program.cs
public static int Main(string[] args)
        {
			int error = 0;
// repository declaration        	
 			repo = xSpector.Repository.Instance;
// define abort test shortcut 
			Keyboard.AbortKey = System.Windows.Forms.Keys.Pause;
            
// Create PopupWatcher
			PopupWatcher myPopupWatcher = new PopupWatcher();
// here are the dialogs I'm watching for...
			myPopupWatcher.Watch(repo.Open.PathDoesNotExistDlgInfo, ClosePopUpDialog); 
			myPopupWatcher.Watch(repo.Error.AnErrorOccuredWhileOpeningFileInfo, ClosePopUpDialog);
			myPopupWatcher.Watch(repo.Error.UnsupportedFileVersionInfo, ClosePopUpDialog);
            
// Start PopupWatcher
			myPopupWatcher.Start(); 			

            try
            {
                error = TestSuiteRunner.Run(typeof(Program), Environment.CommandLine);
            }
            catch (Exception e)
            {
                Report.Error("Unexpected exception occurred: " + e.ToString());
                error = -1;
            }
            return error;
        }

        public static void ClosePopUpDialog(Ranorex.Core.Repository.RepoItemInfo myRepoElement, Ranorex.Core.Element myElement)   
		{   
// if a watched dialog appears, ranorex takes its screenshot, stores it to report and confirms the dialog 
			if (myRepoElement == repo.Error.AnErrorOccuredWhileOpeningFileInfo | myRepoElement == repo.Error.UnsupportedFileVersionInfo )
			{
				Report.Screenshot(repo.Error.Self);
				repo.Error.ButtonOK.Click();  
			}
			else if (myRepoElement == repo.Open.PathDoesNotExistDlgInfo)
			{
	        	Report.Screenshot(repo.Open.PathDoesNotExistDlg); 
	 			repo.Open.PathDoesNotExistBtnOK.Click();  
			}
		}
Of course, you can extend the report with logged dialog title or whatever you want. Just add Report.Log before/after Report.Screenshot line. 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

kmck
Certified Professional
Certified Professional
Posts: 83
Joined: Fri Jul 12, 2013 2:41 pm

Re: Report failure with PopupWatcher

Post by kmck » Mon Jan 27, 2014 10:40 pm

Hi odklizec,

Thank you for your help, this actually worked well in reporting a failure in the report, but at the top level it showed no failure (i.e. the pie chart shows all green, but if I open up all the recordings I can find where the unexpected dialogue popped up and there is the failure.)

Does this happen with yours?

The issue is that, at first glance, it looks like everything is fine, but there's a sneaky failure hidden within that nobody would know to look for.

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

Re: Report failure with PopupWatcher

Post by odklizec » Mon Jan 27, 2014 11:05 pm

Hi,

Yes, this is unfortunately a problem caused by the fact the PopupWatcher is run in a separated thread. Fortunately, there is a relative easy solution of that problem. See this discussion...
http://www.ranorex.com/forum/popupwatch ... t5647.html
Basically, you need to create a User Code action in your recording and inside this user code you need to evaluate a global variable set by the PopupWatcher method. Then in case you want to stop the test execution on the popup appearance, use "throw new exception". If you just want to mark the test case/iteration failed but continue with the test execution, use "Validate.IsFalse". 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

kmck
Certified Professional
Certified Professional
Posts: 83
Joined: Fri Jul 12, 2013 2:41 pm

Re: Report failure with PopupWatcher

Post by kmck » Tue Feb 04, 2014 10:45 pm

Hi odklizec,

Thank you for pointing me over to that thread; that definitely would work for the recordings where I know where to expect the popup, but I have a couple in my Program.cs file where the popup can occur at any point in the project, so it makes it quite a bit more difficult to implement that workaround. :(

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

Re: Report failure with PopupWatcher

Post by odklizec » Wed Feb 05, 2014 8:33 am

Hi,

In this case, you need to add the User Code action (for evaluating global variable) to each recording module.

Of course, it may be a bit difficult or annoying to do in case of hundreds recording modules, but definitely not impossible? Program.cs will remain the same as well as the content of User Code method. To make the things easier, it would be good to put the user code method to a "common" class. Then you don't have to put this method to each Recording UserCode.cs. You just need to make the common class inherited by each recording module, e.g. like this...
In YourRecordingModule.UserCode.cs modify the module declaration (in case of too many recordings, I would use batch file editing):
public partial class YourRecordingModule : CodeModules.CommonFunctions
Then in Recording view, you should be able to add the UserCode action, inherited from the common class. 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