6 Answers, 1 is accepted
0
Hello SD,
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
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 ?
Ta.
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
Hi Seth,
I used your exact code:
and your exact Using statements:
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,
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));
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
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:
needs to change to (for instance):
Kind regards,
Stoich
the Telerik team
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"
);
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
Test Studio Trainings