Image comparasion validation problems : Automation API

Image comparasion validation problems

Class library usage, coding and language questions.

Image comparasion validation problems

Postby slavikf » Tue Mar 29, 2011 9: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: 97
Joined: Mon Sep 13, 2010 10:07 pm
Location: Toronto, Canada

Re: Image comparasion validation problems

Postby slavikf » Wed Mar 30, 2011 12:04 am

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
slavikf
 
Posts: 97
Joined: Mon Sep 13, 2010 10:07 pm
Location: Toronto, Canada

Re: Image comparasion validation problems

Postby Support Team » Wed Mar 30, 2011 12:31 am

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
User avatar
Support Team
Site Admin
 
Posts: 4845
Joined: Fri Jul 07, 2006 5:30 pm
Location: Graz, Austria


Return to Automation API

Who is online

Users browsing this forum: No registered users and 0 guests

cron