Image comparasion validation problems

Class library usage, coding and language questions.
User avatar
slavikf
Posts: 104
Joined: Mon Sep 13, 2010 9:07 pm
Location: Toronto, Canada
Contact:

Image comparasion validation problems

Post by slavikf » Tue Mar 29, 2011 8:01 pm

I can't make image comparasion to work.
Here are steps to reproduce:
* In Recorder, record following steps:
- start msPaint
- open some existing image from the disk
* start Ranorex Spy, capture screenshot of that image in msPaint (ElementMspaint), save it to "C:\captureTest\test.png"
* add validation code to the script:

Code: Select all

Bitmap image = Imaging.Load ("C:\\captureTest\\test.png");
Validate.ContainsImage (repo.FormScreenShot_png___Paint.ElementMspaintInfo,
	image,
	Imaging.FindOptions.Default,
	"Validation: All figures are correctly drawn");
It fails all the time. Why?

User avatar
slavikf
Posts: 104
Joined: Mon Sep 13, 2010 9:07 pm
Location: Toronto, Canada
Contact:

Re: Image comparasion validation problems

Post by slavikf » Tue Mar 29, 2011 11:04 pm

In my AUT following code fails:
Bitmap image;
image = Imaging.CaptureImage (repo.FormWinstn2.ElementN59648);
image.Save (RestoreDB.SSDir+"TC611.png",ImageFormat.Png);
			
image = Imaging.Load (RestoreDB.SSDir+"TC611.png");
Validate.ContainsImage(repo.FormWinstn2.ElementN59648Info,
					image,
					Imaging.FindOptions.Default, 
					"TC611: Validation: file",
					false);
Image saved, then loaded immediately and compared and it failed! How that possible? Application doesn't change anything during that moment on screen.
Please, help.

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

Re: Image comparasion validation problems

Post by Support Team » Tue Mar 29, 2011 11:31 pm

Hello,

I've modified your code in order to reproduce a possible problem:
Bitmap image;  
   image = Imaging.CaptureImage (TestForKimRepository.Instance.FormVIP_Database.ButtonAdd);  
   image.Save (@"c:\temp\TC611.png",System.Drawing.Imaging.ImageFormat.Png);
                 
   image = Imaging.Load (@"c:\temp\TC611.png");  
   Validate.ContainsImage(TestForKimRepository.Instance.FormVIP_Database.ButtonAddInfo,  
                       image,  
                       Imaging.FindOptions.Default,   
                       "TC611: Validation: file",  
                       false);
My modified version works. So there shouldn't be any principle problem.

ElementN59648 creates an adapter which means that your desktop is searched for the element. With ElementN59648Info later your desktop is searched again and a new adapter is created. Could you try something like this
Bitmap image;  
   Ranorex.Core.Element el = repo.FormWinstn2.ElementN59648;
   image = Imaging.CaptureImage (el);  
   image.Save (RestoreDB.SSDir+"TC611.png",System.Drawing.Imaging.ImageFormat.Png);

   image = Imaging.Load (RestoreDB.SSDir+"TC611.png");  
   Validate.ContainsImage(el,
                       image,  
                       Imaging.FindOptions.Default,   
                       "TC611: Validation: file",  
                       false);
Next thing to try would be the FindOptions tuning (e.g. Similarity).
It could be that the successive screenshots are not completely identical.

Regards,
Roland
Ranorex Support Team
.
Image