Page 1 of 1

Log Message only if previous action fails

Posted: Tue Mar 21, 2017 11:35 am
by Andrea
Hi!

I want to add a 'Log Message' action into the module which should report the result of the previous action. Preferably only apply if the previous action fails. How would I do this?

Best,
Andrea

Re: Log Message only if previous action fails

Posted: Tue Mar 21, 2017 3:31 pm
by krstcs
Why do you need this? I'm not sure I understand the use case.

Ranorex already reports any failures by default, so not sure what else you are wanting. And, you usually want the report to be at the point of failure, not later.

Re: Log Message only if previous action fails

Posted: Thu Apr 20, 2017 3:51 pm
by Andrea
OK, I think I need to be more clear

The testcase I am refering to is sort of the following

action 1: open file
action 2: confirm pop up window [since the appearing of the window is non-deterministic I use continue on fail for this action)
action 3: log message: pop up window

Now, if possible I would like to have the log message only reported if action 2 fails (=no pop up window appears). Just for readibility reasons.

Re: Log Message only if previous action fails

Posted: Fri Apr 21, 2017 1:01 pm
by qwertzu
Hello Andrea,

Thank you for the details.

I would suggest adding a "Validate Exists"- action that validates if the popup window exists.
If not, an error will be thrown.
validateExists.png
I hope, this helps.

Regards,

qwertzu

Re: Log Message only if previous action fails

Posted: Fri Apr 21, 2017 3:57 pm
by Andrea
Hi qwertzu,

thanks for your reply, but thats not exactly what I am looking.
I use the 3 steps for several iterations, in some iteration the pop up window appear in others not. If they appear the testrunner has to press an OK button. But in iterations where the windows does not appears no press needed.
As I do not want that thoese iterations fail I put the action to continue on fail because a not-appearing pop up window not means that the test is fails. Therefore I want to add a log message somewhat like "pop up window not appearing" as additional info, so that the reader of the report knows, that it is not a failure.

if it is not possible to add this only in the case of a failed action I will add it in general.

Best,
Andrea

Re: Log Message only if previous action fails

Posted: Fri Apr 21, 2017 4:35 pm
by krstcs
First, you should know on each test case/scenario exactly which popups should appear and why. If you don't, then you may need to talk to your developers and find out more about the situation so you know how to automate it correctly.

Second, if this is truly a 'random' popup and you can't ever know if/when it will happen, then you should probably be using a PopupWatcher to catch it and click the OK button for you. This will keep it from failing if it is there, or if it isn't. You can find out more about using the PopupWatcher class in the UserGuide and specifically this link: http://www.ranorex.com/support/user-gui ... html#c4678.

Re: Log Message only if previous action fails

Posted: Wed Apr 26, 2017 10:59 am
by Andymann
We do this by using a piece of UserCode: ClickIfExists

Code: Select all

public void clickIfExists(Ranorex.Core.Repository.RepoItemInfo pItem, int pTimeoutSeconds){
			try{
				Ranorex.Unknown pElement = Host.Local.FindSingle( pItem.AbsolutePath, pTimeoutSeconds * 1000 );
				if(pElement != null){
					pElement.Click();
					Ranorex.Report.Info("clickIfExists() auf Item " + pItem.Name);
				}
			}catch(Exception e){
					//Console.Out.WriteLine("SuperTools.clickIfExists() Exception:" + e.Message);
					Ranorex.Report.Info("clickIfExists() Item " + pItem.Name + " nicht gefunden. Kein Klick.");
			}			
		}
It could probably be improved by using "TryFindSingle" instead of "FindSingle" but it does the job.

(The basic problem behind it - a non-predictable behaviour of the apllication under test- is still there, of course)

Re: Log Message only if previous action fails

Posted: Tue May 09, 2017 1:56 pm
by Andrea
Hi,

thanks for your input, will give it a try.

Best,
Andrea