Log Message only if previous action fails

Best practices, code snippets for common functionality, examples, and guidelines.
Andrea
Posts: 8
Joined: Fri Dec 16, 2016 1:48 pm

Log Message only if previous action fails

Post by Andrea » Tue Mar 21, 2017 11:35 am

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

krstcs
Ranorex Guru
Posts: 2683
Joined: Tue Feb 07, 2012 4:14 pm
Location: Austin, Texas, USA

Re: Log Message only if previous action fails

Post by krstcs » Tue Mar 21, 2017 3:31 pm

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.
Shortcuts usually aren't...

Andrea
Posts: 8
Joined: Fri Dec 16, 2016 1:48 pm

Re: Log Message only if previous action fails

Post by Andrea » Thu Apr 20, 2017 3:51 pm

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.

qwertzu
Posts: 178
Joined: Wed Jan 25, 2017 11:08 am

Re: Log Message only if previous action fails

Post by qwertzu » Fri Apr 21, 2017 1:01 pm

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
validateExists.png (5.81 KiB) Viewed 666 times
I hope, this helps.

Regards,

qwertzu

Andrea
Posts: 8
Joined: Fri Dec 16, 2016 1:48 pm

Re: Log Message only if previous action fails

Post by Andrea » Fri Apr 21, 2017 3:57 pm

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

krstcs
Ranorex Guru
Posts: 2683
Joined: Tue Feb 07, 2012 4:14 pm
Location: Austin, Texas, USA

Re: Log Message only if previous action fails

Post by krstcs » Fri Apr 21, 2017 4:35 pm

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.
Shortcuts usually aren't...

User avatar
Andymann
Posts: 41
Joined: Wed Jul 27, 2016 12:22 pm
Location: Hamburg
Contact:

Re: Log Message only if previous action fails

Post by Andymann » Wed Apr 26, 2017 10:59 am

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)
Vorsprung durch Wahnsinn
www.Doktor-Andy.de

Andrea
Posts: 8
Joined: Fri Dec 16, 2016 1:48 pm

Re: Log Message only if previous action fails

Post by Andrea » Tue May 09, 2017 1:56 pm

Hi,

thanks for your input, will give it a try.

Best,
Andrea