Continue Script Automatically after Failure

Ranorex Studio, Spy, Recorder, and Driver.
patik
Posts: 2
Joined: Tue Feb 24, 2009 2:49 pm

Continue Script Automatically after Failure

Post by patik » Tue Feb 24, 2009 3:03 pm

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

User avatar
Support Team
Site Admin
Site Admin
Posts: 12145
Joined: Fri Jul 07, 2006 4:30 pm
Location: Houston, Texas, USA
Contact:

Post by Support Team » Thu Feb 26, 2009 8:49 am

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

ohm
Posts: 27
Joined: Thu Dec 03, 2009 7:27 pm

Re: Continue Script Automatically after Failure

Post by ohm » Wed Dec 23, 2009 4:08 pm

To do this, I have to turn all the validations to user code and edit each one?
I have many validations in my script.

User avatar
Support Team
Site Admin
Site Admin
Posts: 12145
Joined: Fri Jul 07, 2006 4:30 pm
Location: Houston, Texas, USA
Contact:

Re: Continue Script Automatically after Failure

Post by Support Team » Wed Dec 23, 2009 4:17 pm

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

ohm
Posts: 27
Joined: Thu Dec 03, 2009 7:27 pm

Re: Continue Script Automatically after Failure

Post by ohm » Wed Dec 23, 2009 8:56 pm

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.

ohm
Posts: 27
Joined: Thu Dec 03, 2009 7:27 pm

Re: Continue Script Automatically after Failure

Post by ohm » Wed Dec 23, 2009 10:16 pm

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 :)

ohm
Posts: 27
Joined: Thu Dec 03, 2009 7:27 pm

Re: Continue Script Automatically after Failure

Post by ohm » Thu Dec 24, 2009 12:05 am

Now reports don't include the screenshots. Is there any way to get the full reports with screenshots?

User avatar
Support Team
Site Admin
Site Admin
Posts: 12145
Joined: Fri Jul 07, 2006 4:30 pm
Location: Houston, Texas, USA
Contact:

Re: Continue Script Automatically after Failure

Post by Support Team » Thu Dec 24, 2009 3:14 pm

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

ohm
Posts: 27
Joined: Thu Dec 03, 2009 7:27 pm

Re: Continue Script Automatically after Failure

Post by ohm » Mon Dec 28, 2009 4:17 pm

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.

User avatar
Support Team
Site Admin
Site Admin
Posts: 12145
Joined: Fri Jul 07, 2006 4:30 pm
Location: Houston, Texas, USA
Contact:

Re: Continue Script Automatically after Failure

Post by Support Team » Tue Dec 29, 2009 12:36 pm

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

ohm
Posts: 27
Joined: Thu Dec 03, 2009 7:27 pm

Re: Continue Script Automatically after Failure

Post by ohm » Tue Dec 29, 2009 3:34 pm

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.

User avatar
Support Team
Site Admin
Site Admin
Posts: 12145
Joined: Fri Jul 07, 2006 4:30 pm
Location: Houston, Texas, USA
Contact:

Re: Continue Script Automatically after Failure

Post by Support Team » Sat Jan 02, 2010 10:12 pm

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

User avatar
Support Team
Site Admin
Site Admin
Posts: 12145
Joined: Fri Jul 07, 2006 4:30 pm
Location: Houston, Texas, USA
Contact:

Re: Continue Script Automatically after Failure

Post by Support Team » Wed Jul 27, 2011 3:09 pm

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