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
Report failure with PopupWatcher
Re: Report failure with PopupWatcher
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
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
Re: Report failure with PopupWatcher
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.
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.
Re: Report failure with PopupWatcher
Hi,
I'm using PopupWatcher to save a screenshot of popup window just before its closure.
This code goes to Program.cs
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 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
Re: Report failure with PopupWatcher
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.
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.
Re: Report failure with PopupWatcher
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?
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 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
Re: Report failure with PopupWatcher
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.
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.
Re: Report failure with PopupWatcher
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 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.CommonFunctionsThen 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 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