Have PopupWatcher Set ReportLevel to Failure

Class library usage, coding and language questions.
loonquawl
Posts: 49
Joined: Wed Nov 22, 2017 10:08 am

Have PopupWatcher Set ReportLevel to Failure

Post by loonquawl » Thu Feb 08, 2018 9:44 am

Hi.

I'm working with Ranorex 8.0.1, and have the AutomationHelpers installed.
What i would like to achive is to have a Failure reported in case a certain Popup appears, but leave the test running. The two ways to achive that that i see is to somehow leverage the click-action to generate a failure-report (can't think of how though), or have a special UserCodeMethod "StartFailWatcher" that i can use instead of the usual "StartPopupWatcher" that i want to use for the other sorts of popups - what i have right now is this:

Code: Select all

[UserCodeMethod]
		public static PopupWatcher StartFailWatcher(RepoItemInfo findElement, RepoItemInfo clickElement)
		{
			var key = findElement.GetMetaInfos()["id"] + clickElement.GetMetaInfos()["id"];

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

			var watcher = new PopupWatcher();
			watcher.WatchAndClick(findElement, clickElement);
			watcher.EnableReportMessages = true; // enables logging of this watcher
         watcher.ReportCategory = "Failure"; // the logging is done as 'Failure'        <-----------
			watcher.Start();
			watchers.Add(key, watcher);
			Report.Info("Popup watcher started.");
			return watcher;
		}
the problem being that "ReportCategory" is just a flavor of text, with no ramifications as to the Fail-Count of the test. What i would need would be to set "ReportLevel", but that method seems to not be implemented for the PopupWatcher class.
any ideas how to achieve my goal? (Goal being to generate a Failure in the report, on triggering the PopupWatcher - whether with this UserCodeMethod or any other means, i don't care)

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

Re: Have PopupWatcher Set ReportLevel to Failure

Post by odklizec » Thu Feb 08, 2018 11:46 am

Hi;

The problem is, that the PopupWatcher runs in a separate thread and there is currently no way to pause/stop the main thread form it, although one user reported a success with stopping the test using certain code. See his post here:
https://www.ranorex.com/forum/how-to-fa ... tml#p46702
There is mentioned another workaround above that post and link to user voice, where you can vote for the PopupWatcher improvements.
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

loonquawl
Posts: 49
Joined: Wed Nov 22, 2017 10:08 am

Re: Have PopupWatcher Set ReportLevel to Failure

Post by loonquawl » Thu Feb 08, 2018 3:47 pm

Thanks for the link!
As mentioned elsewhere, i am not that firm in C#; so i will ask to be certain i understood and was understood:
Why is it impossible to log a failure without stopping the thread? the one Attributeis report.ReportCategory, the other is report.ReportLevel - The "category" one gets mentioned in the report, why can't the "level" one be taken into account as well? - I do not want the execution to deviate, the test can roll on just fine - i just need the report to later call the TestCase-loop, which it had to intervene in, a failure, so the statistic in the upper right hand corner says something like 48x Success, 2x Fail (where the 2x Fail where the iterations that this specific Popupwatcher had to intervene).
Slightly less useful, but also still acceptable would be to have a sentence at the very top of the report: " SpecialPopupwatcher had to intervene x times " or "Special popuopwatcher intervened in x/50, y/50,z/50"
Is there no Flag to set, no global variable to achieve that?

thanks!

loonquawl
Posts: 49
Joined: Wed Nov 22, 2017 10:08 am

Re: Have PopupWatcher Set ReportLevel to Failure

Post by loonquawl » Thu Feb 15, 2018 11:03 am

I've been mulling this over - i'm not versed enough in C# to know how, but there must be a way to set some parameter/flag from within a (modified?) popupwatcher, and later (in the Teardown?) have another module set the containing SmartFolder-executions and TestCase-executions to "Failure" in the report.

the different Threads are only a problem for realtime meddling, but the popupwatcher gets integrated into the Report at the corresponding time, so there should be no problem in tweaking the report further.

Can anybody advise?

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

Re: Have PopupWatcher Set ReportLevel to Failure

Post by odklizec » Thu Feb 15, 2018 2:11 pm

Hi,

I'm afraid, I'm not so skilled in C# too, especially not in multi-threaded coding. All I know is that there is really no way to control the main test thread from popupwatcher thread. But it may be just a limitation of current popupwatcher implementation?

Yes, it's possible to write things to report (from popupwatcher), but that's about it. And yes, there really is a way to kill the test from popupwatcher (using the code mentioned here). Unfortunately, even if you use ReportLevel.Failure (from popupwatcher), it will not set the test as failed! This is as best as you can currently get with popupwatcher...:
Popupwatcher_failure.png
Popupwatcher_failure.png (51.27 KiB) Viewed 360 times
And one more thing about killing test from popupwatcher...you should first close the report, before killing test, otherwise, it may be incomplete or impossible to open ;) This is an example of "watch" method that should write "failure" to report and kill test...

Code: Select all

public static void watchMethod(RepoItemInfo myInfo, Ranorex.Core.Element myElement)
{
	Report.Screenshot(ReportLevel.Failure, "PopupWatcher", "An error occured!",myElement.Parent.Parent, true,null);
	Ranorex.Core.Reporting.TestReport.EndTestCaseContainer();
	Ranorex.Core.Reporting.TestReport.SaveReport();
	Environment.Exit(-1);
}
PS: feel free to vote for improved popupwatcher here:
https://uservoice.ranorex.com/forums/15 ... from-popup
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