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
Continue Script Automatically after Failure
- Support Team
- Site Admin
- Posts: 12145
- Joined: Fri Jul 07, 2006 4:30 pm
- Location: Houston, Texas, USA
- Contact:
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:
best regards,
Christoph,
Ranorex Support Team
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);
}
Christoph,
Ranorex Support Team
Re: Continue Script Automatically after Failure
To do this, I have to turn all the validations to user code and edit each one?
I have many validations in my script.
I have many validations in my script.
- Support Team
- Site Admin
- Posts: 12145
- Joined: Fri Jul 07, 2006 4:30 pm
- Location: Houston, Texas, USA
- Contact:
Re: Continue Script Automatically after Failure
No, just set the "Exception on Fail" property of all the validation items to false.ohm wrote:To do this, I have to turn all the validations to user code and edit each one?
See http://www.ranorex.com/support/user-gui ... ation.html
Regards,
Alex
Ranorex Support Team
Re: Continue Script Automatically after Failure
Thanks Alex.
Great! It works from rxrec.
Is there any way to do it from the usercode?
Lets say I have the following code:
I tried to add "false" at the end. Did not work.
Thanks in advance.
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");
Thanks in advance.
Re: Continue Script Automatically after Failure
Found it.
It should be:
Thanks anyway
It should be:
Code: Select all
Validate.IsTrue(repo.Browser.no_resultInfo.Exists() || repo.Browser.yes_resultInfo.Exists(), Validate.DefaultMessage, false);
Re: Continue Script Automatically after Failure
Now reports don't include the screenshots. Is there any way to get the full reports with screenshots?
- Support Team
- Site Admin
- Posts: 12145
- Joined: Fri Jul 07, 2006 4:30 pm
- Location: Houston, Texas, USA
- Contact:
Re: Continue Script Automatically after Failure
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
http://www.ranorex.com/Documentation/Ra ... Report.htm
Regards,
Alex
Ranorex Support Team
Re: Continue Script Automatically after Failure
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:
I have tried changing the 'Use Default Logging' to 'Default'/'True'/'False'. No luck.
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;
}
- Support Team
- Site Admin
- Posts: 12145
- Joined: Fri Jul 07, 2006 4:30 pm
- Location: Houston, Texas, USA
- Contact:
Re: Continue Script Automatically after Failure
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:
Alex
Ranorex Support Team
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
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.
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.
- Support Team
- Site Admin
- Posts: 12145
- Joined: Fri Jul 07, 2006 4:30 pm
- Location: Houston, Texas, USA
- Contact:
Re: Continue Script Automatically after Failure
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:So to continue after failure and get a screenshot I need to convert my recordings to user codes.
... that's why I filed a feature request in our wanted-features database.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.
Thanks, hope you had some great holidays, too!ohm wrote:Enjoy a nice and safe holiday season.
Regards,
Alex
Ranorex Support Team
- Support Team
- Site Admin
- Posts: 12145
- Joined: Fri Jul 07, 2006 4:30 pm
- Location: Houston, Texas, USA
- Contact:
Re: Continue Script Automatically after Failure
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
Regards,
Alex
Ranorex Team