- (in a try statement)Ranorex searches for the element
- The search times out because the element is not on screen (@visible='True' failed)
- The timeout throws a ValidationException
- The exception is caught by the catch statement
- The catch statement logs a 5 second delay
- The catch statement hits the PageDown key once.
- The code loops back to the try statement
- If the code hits the final loop and the search fails, the exception is thrown and the test ends.
Catching exceptions but report says module still failed
Catching exceptions but report says module still failed
I have a try/catch set up for one of my tests because I have to have @visible='True' in part of my RxPath. The user code has parameters set up to loop 12 times through the try/catch explained below:
You do not have the required permissions to view the files attached to this post.
- Support Team
- Site Admin
- Posts: 12145
- Joined: Fri Jul 07, 2006 4:30 pm
- Location: Houston, Texas, USA
- Contact:
Re: Catching exceptions but report says module still failed
Hi ksanowski,
The validation > attributeequals method does provide an overload that allows you to disable the thrown exception, however, it is going to report a failure regardless. Disabling the thrown exception will simply prevent the need of a try/catch block.
Note, the Validate.AttributeEqual method specifically returns a bool so you can use a simple if statement instead of a try/catch.
However, the above still does not resolve your false failure report entries since the report messages occur regardless. I recommend using a get attribute value to check the attribute value yourself as this does not contain any report entries automatically. Once it is successful/fails, use a Report.Fail/Validate.Fail/Report.Success. Here is a small example I hope helps get you pointed in the right direction.
I hope this helps!
Cheers,
Ned
The validation > attributeequals method does provide an overload that allows you to disable the thrown exception, however, it is going to report a failure regardless. Disabling the thrown exception will simply prevent the need of a try/catch block.
Note, the Validate.AttributeEqual method specifically returns a bool so you can use a simple if statement instead of a try/catch.
Code: Select all
if (!Validate.AttributeEqual(textelement, "text", "123", "Does not match", false))
Report.Info("Does not match!");
Code: Select all
for (int i = 0; i < 10; i++)
{
if(textelement.GetAttributeValue<string>("text") == "123")
{
Report.Success("Attribute equals 123!");
return;
}
else
{
Report.Info("attribute did not continuing search...");
Delay.Seconds(5);
}
}
Validate.Fail("Text attribute never matched 123");
Cheers,
Ned