Ranorex Enable Continue on Fail Validate istrue
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
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
-
- 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:
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
To do this, I have to turn all the validations to user code and edit each one?
I have many validations in my script.
- ohm
- Posts: 27
- Joined: Thu Dec 03, 2009 7:27 pm
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:
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
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
Now reports don't include the screenshots. Is there any way to get the full reports with screenshots?
- ohm
- Posts: 27
- Joined: Thu Dec 03, 2009 7:27 pm
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:
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.
-
- 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:
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
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.
-
- Site Admin
- Posts: 12145
- Joined: Fri Jul 07, 2006 4:30 pm
- Location: Houston, Texas, USA
- Contact:
Re: Continue Script Automatically after Failure
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
-
- 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
Source: https://www.ranorex.info/continue-script-automatically-after-failure-t666.html
0 Response to "Ranorex Enable Continue on Fail Validate istrue"
Post a Comment