Catching exceptions but report says module still failed

Ask general questions here.
Posts: 3
Joined: Fri May 24, 2019 5:29 pm

Catching exceptions but report says module still failed

Post by ksanowski » Wed Jun 19, 2019 12:44 am

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:
  • (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.
The try/catch is working perfectly as intended EXCEPT at the end of the test, I get this error logged and the test is recorded as failed:
rxscreenshot.PNG (40.49 KiB) Viewed 426 times
I understand that some actions failed but they were caught by the try/catch statement and handled in a way that the test continued. It isn't a MAJOR issue but it does result in the test case listed as failed when, in reality, it was working as intended:
rxresults.png (58.55 KiB) Viewed 426 times
Is there something I can do that will cause the test to be listed as successful? The screenshot below shows the error message in the report where the try/catch loop is operating until the element is found. The search only needs 10 seconds; the element is found within 0.4 seconds when it is on-screen but the try/catch doesn't hit the PageDown key until the exception is thrown:
rxscreenshot1.PNG (95.36 KiB) Viewed 426 times

User avatar
Support Team
Site Admin
Site Admin
Posts: 12143
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: Catching exceptions but report says module still failed

Post by Support Team » Wed Jun 19, 2019 9:38 pm

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.

Code: Select all

if (!Validate.AttributeEqual(textelement, "text", "123", "Does not match", false))
	Report.Info("Does not match!");
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.

Code: Select all

for (int i = 0; i < 10; i++) 
	if(textelement.GetAttributeValue<string>("text") == "123")
		Report.Success("Attribute equals 123!");
		Report.Info("attribute did not  continuing search...");
Validate.Fail("Text attribute never matched 123");
I hope this helps!