Page 1 of 1

Continue Script Automatically after Failure

Posted: Tue Feb 24, 2009 3:03 pm
by patik
Hi

Newbie to using ranorex, currently evaluating and I was wondering, is there a way to allow my script to continue even if there is a failure. At the moment the Ranorex will stop where it has failed, and the log shows all the stages up to this point. If I then continue my script from where it failed manually but no log is created or appends to the existing one.

What I would prefer is that the playback, just continues and if something fails, takes the screen shot, and proceeds and logs this aswell.

This would be very useful if it cannot be done as a improvement. i.e. if a validation fails(default should be 0 but shown as 2), all other parts could still potentially be tested, as it may not affect them.

Any feedback or help would be welcomed.

Patik

Posted: Thu Feb 26, 2009 8:49 am
by Support Team
Hi,

Within Ranorex code you can use the Validate class to check values of GUI elements. Additionally, you can specify whether the validation should throw an exception or not:

Code: Select all

bool result = Validate.AreEqual(button.Text, "Text of my button","Validate button text", false);

if ( result == false )
{
  Report.Screenshot(Host.Local);
  // or
  Report.Screenshot(button);
}
best regards,

Christoph,
Ranorex Support Team

Re: Continue Script Automatically after Failure

Posted: Wed Dec 23, 2009 4:08 pm
by ohm
To do this, I have to turn all the validations to user code and edit each one?
I have many validations in my script.

Re: Continue Script Automatically after Failure

Posted: Wed Dec 23, 2009 4:17 pm
by Support Team
ohm wrote:To do this, I have to turn all the validations to user code and edit each one?
No, just set the "Exception on Fail" property of all the validation items to false.
See http://www.ranorex.com/support/user-gui ... ation.html

Regards,
Alex
Ranorex Support Team

Re: Continue Script Automatically after Failure

Posted: Wed Dec 23, 2009 8:56 pm
by ohm
Thanks Alex.
Great! It works from rxrec.

Is there any way to do it from the usercode?

Lets say I have the following code:

Code: Select all

Validate.IsTrue(repo.Browser.no_resultInfo.Exists() || repo.Browser.yes_resultInfo.Exists(), "'Sorry no results' or 'Search results' is present");
I tried to add "false" at the end. Did not work.

Thanks in advance.

Re: Continue Script Automatically after Failure

Posted: Wed Dec 23, 2009 10:16 pm
by ohm
Found it.

It should be:

Code: Select all

Validate.IsTrue(repo.Browser.no_resultInfo.Exists() || repo.Browser.yes_resultInfo.Exists(), Validate.DefaultMessage, false);
Thanks anyway :)

Re: Continue Script Automatically after Failure

Posted: Thu Dec 24, 2009 12:05 am
by ohm
Now reports don't include the screenshots. Is there any way to get the full reports with screenshots?

Re: Continue Script Automatically after Failure

Posted: Thu Dec 24, 2009 3:14 pm
by Support Team
You can simply create a screenshot in the report by calling the Report.Screenshot method. See the documentation of the Report class for more info:
http://www.ranorex.com/Documentation/Ra ... Report.htm

Regards,
Alex
Ranorex Support Team

Re: Continue Script Automatically after Failure

Posted: Mon Dec 28, 2009 4:17 pm
by ohm
Thanks Alex.

Lets say I am working with Recording1.rxrec and in one of the validation properties I select 'Exception On Fail' to 'False'. So when I run my test it does not stop when it fails to validate. But it does not include any screenshot in the report. Even though I have the following code in my Program.cs:

Code: Select all

catch (ImageNotFoundException e)
            {
                Report.Error(e.ToString());
                Report.Screenshot();
                Report.LogData(ReportLevel.Error, "Image not found", e.Feature);
                Report.LogData(ReportLevel.Error, "Searched image", e.Image);
                error = -1;
            }
            catch (RanorexException e)
            {
                Report.Error(e.ToString());
                Report.Screenshot();
                error = -1;
            }
            catch (ThreadAbortException)
            {
                Report.Warn("AbortKey has been pressed");
                Report.Screenshot();
                Thread.ResetAbort();
            }
            catch (Exception e)
            {
                Report.Error("Unexpected exception occured: " + e.ToString());
                error = -1;
            }
I have tried changing the 'Use Default Logging' to 'Default'/'True'/'False'. No luck.

Re: Continue Script Automatically after Failure

Posted: Tue Dec 29, 2009 12:36 pm
by Support Team
A validation, no matter whether it fails or succeeds, does not generate a screenshot by default, the screenshot is produced by the "catch (RanorexException e)" statements. If you set the property "Exception on Fail" to false, this exception handler is not invoked, since no exception is thrown.

If you want a screenshot to be generated for a failed validation, you need to add the code yourself, i.e. by changing the validation action to a User Code action. See the following sample code:
if (!Validate.Attribute(repo.FormRechner.Button1Info, "Text", "yourtext", Validate.DefaultMessage, false))
{
    // add screenshot to report if validation fails
    Report.Screenshot();
}
Regards,
Alex
Ranorex Support Team

Re: Continue Script Automatically after Failure

Posted: Tue Dec 29, 2009 3:34 pm
by ohm
So to continue after failure and get a screenshot I need to convert my recordings to user codes.

May be you guys should put it in your future improvement list so users can use it from 'Properties' without having to go through user codes. It is really helpful when you get a screenshot with your error message.

Thanks again.
Have a great day!
Enjoy a nice and safe holiday season.

Re: Continue Script Automatically after Failure

Posted: Sat Jan 02, 2010 10:12 pm
by Support Team
ohm wrote:So to continue after failure and get a screenshot I need to convert my recordings to user codes.
Right. Actually validations were not meant to create screenshots at all. The screenshot you get by default when a validation fails comes from the "catch (RanorexException e)" clause. But I see your point...
ohm wrote:May be you guys should put it in your future improvement list so users can use it from 'Properties' without having to go through user codes. It is really helpful when you get a screenshot with your error message.
... that's why I filed a feature request in our wanted-features database.
ohm wrote:Enjoy a nice and safe holiday season.
Thanks, hope you had some great holidays, too!

Regards,
Alex
Ranorex Support Team

Re: Continue Script Automatically after Failure

Posted: Wed Jul 27, 2011 3:09 pm
by Support Team
Just wanted to follow up on this thread to notify everybody that we will add a property to validation actions with Ranorex 3.1 which allows to specify if a screenshot should be created for the validation.

Regards,
Alex
Ranorex Team