How to return success if the comparison of 2 images fails

Class library usage, coding and language questions.
Fandora
Posts: 9
Joined: Thu Apr 30, 2015 2:55 pm

How to return success if the comparison of 2 images fails

Post by Fandora » Thu Apr 30, 2015 3:09 pm

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
Last edited by Fandora on Mon May 04, 2015 4:28 pm, edited 1 time in total.

User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 7470
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

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

Post by odklizec » Sat May 02, 2015 11:12 am

Hi,

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

Please add these details to your questions:
  • Ranorex Snapshot. Learn how to create one >here<
  • Ranorex xPath of problematic element(s)
  • Ranorex version
  • OS version
  • HW configuration

Fandora
Posts: 9
Joined: Thu Apr 30, 2015 2:55 pm

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

Post by Fandora » Mon May 04, 2015 9:02 am

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.

User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 7470
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

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

Post by odklizec » Mon May 04, 2015 9:57 am

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
Pavel Kudrys
Ranorex explorer at Descartes Systems

Please add these details to your questions:
  • Ranorex Snapshot. Learn how to create one >here<
  • Ranorex xPath of problematic element(s)
  • Ranorex version
  • OS version
  • HW configuration

Fandora
Posts: 9
Joined: Thu Apr 30, 2015 2:55 pm

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

Post by Fandora » Mon May 04, 2015 4:28 pm

Thanks, I will try this

Fandora
Posts: 9
Joined: Thu Apr 30, 2015 2:55 pm

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

Post by Fandora » Mon May 04, 2015 4:51 pm

This works perfectly, thanks a lot!

User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 7470
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

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

Post by odklizec » Mon May 04, 2015 10:37 pm

You are welcome.
Pavel Kudrys
Ranorex explorer at Descartes Systems

Please add these details to your questions:
  • Ranorex Snapshot. Learn how to create one >here<
  • Ranorex xPath of problematic element(s)
  • Ranorex version
  • OS version
  • HW configuration