Page 1 of 1

How to return success if the comparison of 2 images fails

Posted: Thu Apr 30, 2015 3:09 pm
by Fandora
Hello,

I use Ranorex for only a few time and for the need of automation tests, I want return success in case two images are different (one is in the repository, the other is a screenshot of the current screen). The aim of this is to know if elements have moved (and they should have move).

I tried this code :
try
{ 
Validate.CompareImage(info, screenshot,option) //with relevant data here
}
catch (RanorexException e)
{
Report.Success("Hourra!");
}
The problem is that I have both results : the test fails because of the difference between the two images despite the "try" but the text for success is here too!

Thanks a lot

Sorry for my bad english, it's far to be my mother's tongue

Re: How to return success if the comparison of 2 images fails

Posted: Sat May 02, 2015 11:12 am
by odklizec
Hi,

I believe you have to replace the RanorexException with Ranorex.ValidationException to be able to catch and process validation exceptions? Hope this helps? ;)

Re: How to return success if the comparison of 2 images fails

Posted: Mon May 04, 2015 9:02 am
by Fandora
Thanks for your help.
The problem is not totally resolved but it's better.
By replacing RanorexException with Ranorex.ValidationException, when the images are different, the test continues but there is still a report as "failed" for the validate.CompareImage and this results in a "failed" state for the whole test.

Re: How to return success if the comparison of 2 images fails

Posted: Mon May 04, 2015 9:57 am
by odklizec
Hi,

OK, maybe it would be better/cleaner solution to use validation options, instead of try...catch block. This should do the trick...
Validate.Options valOptions = new Validate.Options();  
valOptions.ExceptionOnFail = false;  // disables exception on fail 
valOptions.ReportLevelOnFailure = ReportLevel.Success; // sets report level to success
Validate.CompareImage(repo.app.SelfInfo,app_Screenshot,app_Screenshot_Options,"Success!",valOptions); //compare images

Re: How to return success if the comparison of 2 images fails

Posted: Mon May 04, 2015 4:28 pm
by Fandora
Thanks, I will try this

Re: How to return success if the comparison of 2 images fails

Posted: Mon May 04, 2015 4:51 pm
by Fandora
This works perfectly, thanks a lot!

Re: How to return success if the comparison of 2 images fails

Posted: Mon May 04, 2015 10:37 pm
by odklizec
You are welcome.