This is a migrated thread and some comments may be shown as answers.

Bitmap comparison.

6 Answers 594 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
SD
Top achievements
Rank 1
SD asked on 09 Dec 2010, 03:52 AM
Hi Guys, 

Could you please advice if Webaii 2.0 APIs support some form of Bitmap comparison ? 

ta,
SD.

6 Answers, 1 is accepted

Sort by
0
Cody
Telerik team
answered on 10 Dec 2010, 11:39 PM
Hello SD,

Yes, you should be able to use code something like this:

System.Drawing.Bitmap expectedbmp = new System.Drawing.Bitmap("myExpected.png");
 
HtmlImage img = Find.ById<HtmlImage>("myImageId");
System.Drawing.Bitmap actualbmp = img.Capture();
 
ArtOfTest.Common.PixelMap expected = ArtOfTest.Common.PixelMap.FromBitmap(expectedbmp);
ArtOfTest.Common.PixelMap actual = ArtOfTest.Common.PixelMap.FromBitmap(actualbmp);
 
Assert.IsTrue(expected.Compare(actual, 5.0));

In the above code I am getting the image of a "myImageId" element from the browser and comparing to an expected image stored on disc named "myExpected.png". The comparison is allowing a 5% tolerance meaning there may be up to a 5% difference in the image or else the Assert will fail and cause the test to abort.

Greetings,
Cody
the Telerik team
Interested in Agile Testing? Check out Telerik TV for a recording of Automated Testing in the Agile Environment
0
SD
Top achievements
Rank 1
answered on 12 Dec 2010, 10:54 PM
Ta mate that's highly appreciated. 
0
SD
Top achievements
Rank 1
answered on 12 Dec 2010, 11:15 PM
Hi Cody, 

I'm getting 'The type of namespace PixelMap does not exist in the namespace ArtOfTest.Common error message.  
I'm using the following namespaces in the my lib (And using Webaii 2.0)....What am I missing ? 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Drawing;
 
using ArtOfTest.WebAii.Controls.HtmlControls;
using ArtOfTest.WebAii.Controls.HtmlControls.HtmlAsserts;
using ArtOfTest.WebAii.Core;
using ArtOfTest.WebAii.ObjectModel;
using ArtOfTest.WebAii.TestAttributes;
using ArtOfTest.WebAii.TestTemplates;
using ArtOfTest.WebAii.Win32.Dialogs;
using ArtOfTest.Common;
 
using ArtOfTest.WebAii.Silverlight;
using ArtOfTest.WebAii.Silverlight.UI;
 
using NUnit.Framework;
using Core = NUnit.Core;
using System.Text.RegularExpressions;



Ta.

0
Stoich
Telerik team
answered on 15 Dec 2010, 05:19 PM
Hi Seth,
   I used your exact code:
Copy Code
System.Drawing.Bitmap expectedbmp = new System.Drawing.Bitmap("myExpected.png");
 
HtmlImage img = Find.ById<HtmlImage>("myImageId");
System.Drawing.Bitmap actualbmp = img.Capture();
 
ArtOfTest.Common.PixelMap expected = ArtOfTest.Common.PixelMap.FromBitmap(expectedbmp);
ArtOfTest.Common.PixelMap actual = ArtOfTest.Common.PixelMap.FromBitmap(actualbmp);
 
Assert.IsTrue(expected.Compare(actual, 5.0));

and your exact Using statements:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Drawing;
 
using ArtOfTest.WebAii.Controls.HtmlControls;
using ArtOfTest.WebAii.Controls.HtmlControls.HtmlAsserts;
using ArtOfTest.WebAii.Core;
using ArtOfTest.WebAii.ObjectModel;
using ArtOfTest.WebAii.TestAttributes;
using ArtOfTest.WebAii.TestTemplates;
using ArtOfTest.WebAii.Win32.Dialogs;
using ArtOfTest.Common;
 
using ArtOfTest.WebAii.Silverlight;
using ArtOfTest.WebAii.Silverlight.UI;
 
using NUnit.Framework;
using Core = NUnit.Core;
using System.Text.RegularExpressions;

I used them in an WebAii NUnit test.
I only had problems resolving Drawing and the NUnit assemblies but after I added references to System.Drawing, NUnit.Framework and Nunit.Core - I was able to build the test without any problems.

Are sure you created your project correctly. Here's how I did it:
I created a new Test Project.
From the Solution Explorer I right-clicked:
Add-->New Item-->Test-->WebAii 2010.3-->NUnit

Everything needed to use PixelMap was added automatically for me and I can't see any reason why it wouldn't be for you. What version of WebAii are you using? Go ahead and upgrade to the latest 12.13 release from here in case you're using anything older. Try creating a new Project/Test - your problem might be resolved.

Please let me know how it goes!

Best wishes,
Stoich
the Telerik team
Interested in Agile Testing? Check out Telerik TV for a recording of Automated Testing in the Agile Environment
0
Murali
Top achievements
Rank 1
answered on 20 Jun 2012, 02:15 AM
Hi, i tried the same, it throws exception


ArtOfTest.Common.Design.Exceptions.ExecutionException: Exception thrown executing coded step: '[ImageComapare] : New Coded Step'. ---> System.ArgumentException: Parameter is not valid.
   at System.Drawing.Bitmap..ctor(String filename)
   at TestProject1.WebTest.ImageComapare() in c:\Users\vivid_staff\Documents\Test Studio Projects\SP_DAR130612\WebTest.tstest.cs:line 51
   --- End of inner exception stack trace ---
   at ArtOfTest.WebAii.Design.Execution.ExecutionEngine.InternalExecuteSteps(AutomationStepList stepList, TestResult testResult, Object codeBehindInstance, Boolean& stopExecution)


This is my Code, have placed the flowers1.png in my project folder.



System.Drawing.Bitmap expectedbmp = new System.Drawing.Bitmap("flowers1.png");
HtmlImage img = Find.ById<HtmlImage>("ctl00_PlaceHolderMain_vContentPageContent_MSO_ContentDiv");
System.Drawing.Bitmap actualbmp = img.Capture();
ArtOfTest.Common.PixelMap expected = ArtOfTest.Common.PixelMap.FromBitmap(expectedbmp);
ArtOfTest.Common.PixelMap actual = ArtOfTest.Common.PixelMap.FromBitmap(actualbmp);
Assert.IsTrue(expected.Compare(actual, 5.0));



0
Stoich
Telerik team
answered on 25 Jun 2012, 08:34 AM
Hello Seth,
you're not feeding the correct parameter to the constructor (see screenshot 1).

You need to feed a full path to the constructor. So this line:
System.Drawing.Bitmap expectedbmp = new System.Drawing.Bitmap("flowers1.png");
needs to change to (for instance):
System.Drawing.Bitmap expectedbmp = new System.Drawing.Bitmap("c:\\flowers1.png");

Kind regards,
Stoich
the Telerik team
Quickly become an expert in Test Studio, check out our new training sessions!
Test Studio Trainings
Tags
General Discussions
Asked by
SD
Top achievements
Rank 1
Answers by
Cody
Telerik team
SD
Top achievements
Rank 1
Stoich
Telerik team
Murali
Top achievements
Rank 1
Share this question
or