Validation action generates two error messages if it fails

Ranorex Spy, Recorder, and Studio.
dontbeshy
Posts: 9
Joined: Sun Sep 11, 2016 5:39 am

Validation action generates two error messages if it fails

Post by dontbeshy » Fri Sep 16, 2016 5:27 pm

There is a variable from Data Source and it will be validated with a textbox on web page.
When if fails, the report shows two error message -

1. Failure Validation - Attribute 'Text' of element for item '.....' doesn't match the specified value.

2. Error Module - Module execution was aborted because validation step has failed.


One error message is enough. I don't need the "Error Module" message and want it to keep going on to the end of Data Source. After finished, I will count 'doesn't match' in notepad to see how many rows got wrong values.

Can we disable "abortion" and make it keep going on?
Can we add one variable to the error message "Failure Valiation....."?

Hope the question is clear to understand.

Thanks.

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

Re: Validation action generates two error messages if it fails

Post by krstcs » Fri Sep 16, 2016 6:05 pm

The two messages mean two very different things.

The FAILURE message means that a step in the test module failed. Either a validation failed, an element for the specified path couldn't be found in time, there was an explicit Report-Failure log entry, or some other TEST failure.

The ERROR message means that there was an EXCEPTION thrown by Ranorex due to the failure above in the test code that was unhandled. You can wrap a try-catch block around the code that caused the issue and as long as you don't re-throw the exception, you won't get this ERROR message and your test will continue. This is by design.

If you set the action causing the problem to "Continue on Failure", the exception will not be thrown and you won't get the ERROR message, but the FAILURE will still be noted.

Also, if you include a Report Failure action in your test, you will ONLY get the FAILURE message, not the ERROR message. The ERROR will ONLY be thrown if there is an unhandled exception.

Ranorex Test Suite error handling settings can also be adjusted to account for these ERROR exceptions.


Think of the FAILURE as just a report entry that lets you know why Ranorex threw the exception and the ERROR as Ranorex saying that the exception was unexpected and therefore Ranorex will stop execution of the module at this point.
Shortcuts usually aren't...

dontbeshy
Posts: 9
Joined: Sun Sep 11, 2016 5:39 am

Re: Validation action generates two error messages if it fails

Post by dontbeshy » Fri Sep 16, 2016 6:19 pm

Thanks for quick reply.
I got a search keyword from your post, "Continue on failure" and googled it and found below link.

http://www.ranorex.com/forum/how-to-con ... t9119.html

But the link has no page any more.

Do you know where I can see "Continue on failure" in the Studio?
Also I see the code below in cs file but it's read-only.

I am not sure where I can customize the error message. I just want to add one variable at the end of message. So I can count how many FSRID got wrong values in report file.




Report.Log(ReportLevel.Info, "Validation", "Validating AttributeEqual (Value=$varFSR) on item 'USA.Ctl00Ctl00ContentPlaceHolder1ContentP1'.", repo.USA.Ctl00Ctl00ContentPlaceHolder1ContentP1Info, new RecordItemIndex(1));
Validate.Attribute(repo.USA.Ctl00Ctl00ContentPlaceHolder1ContentP1Info, "Value", varFSR);
Delay.Milliseconds(0);

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

Re: Validation action generates two error messages if it fails

Post by krstcs » Fri Sep 16, 2016 6:27 pm

Continue on failure is an action-level setting. To see/set it, right-click the specific action you want to continue on, and in the popup menu click "Continue on failure". The action will now have brackets ("[]") around it.

I would caution against the use of this method though as it can have other side-effects if you don't fully understand the ramifications.


Sorry, as for customizing the Ranorex generated FAILURE or ERROR messages, I don't believe that is possible as they are automatically generated by Ranorex at the time of the run-time error.

You can put a try-catch block around the Validate.Attribute() call and in your catch block you can specifically create a Report.Failure() line with the message you want displayed for each failure. You can also put your counter in the catch block and count each instance and then print that out at the end of the test.

Code: Select all

try {
  Report.Log(...);
  Validate.Attribute(...);
} catch (RanorexException) {
  MyCount++;
  Report.Failure("<Message here>");
}
Shortcuts usually aren't...

dontbeshy
Posts: 9
Joined: Sun Sep 11, 2016 5:39 am

Re: Validation action generates two error messages if it fails

Post by dontbeshy » Fri Sep 16, 2016 7:08 pm

Yes I also found "Enable Continue on Failure" on the popup window. :)
But I got this message at the end of recording session and the project stopped and aborted.

The module has failed because one or more actions have failed.

Is there the same option for the entire recording module?

I am getting tired now.

Continue on Failure, it should be "DEFAULT". :roll:

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

Re: Validation action generates two error messages if it fails

Post by krstcs » Fri Sep 16, 2016 8:15 pm

No, Continue on Failure should be the EXCEPTION ONLY, and it should be used only very rarely.

Your tests should be designed so that there are no failures. Even on negative testing you should know the correct and expected outcome and should be validating for that expected outcome.

If you design your tests for no failures then when you get a failure you know that there is a bug in the SUT.



If you want the module to be optional, you can right click on it in the suite and set it to optional, which means that even if it fails, the rest of the test case will continue.

If you want the test case to continue even if there are failures, you need to set the Error Behavior on that test case in your test suite to "Continue Iteration" which will still stop that iteration, but will move to the next iteration of that test case, which is the next data set.
Shortcuts usually aren't...