For image comparison, I saw a piece of code here:
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));
My questions are :
1. How to import the System.Drawing.Bitmap to Telerik? (Also other files)
2. Where is the path for "myExpected.png", should I use "C:\myExpected.png" or just put under the project folder using "myExpected.png"
Thanks
Waylon
9 Answers, 1 is accepted
Add the System.Drawing reference to the Project by following these steps:
1. Click the Project tab.
2. Click the Show button in the Setting ribbon.
3. Click Script Options in the left column of User Settings.
4. Click "Add Reference."
5. Browse to the following folder:
32-bit machine: C:\Program Files\Reference Assemblies\Microsoft\Framework\.NETFramework\v3.5\Profile\Client
64-bit machine: C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v3.5\Profile\Client
6. Choose System.Drawing.dll and click Open.
This KB article goes into more detail on adding Assembly References.
According to this MSDN article, the file name and path can be relative to the application or an absolute path.
Kind regards,
Anthony
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get now >>
Does the image comparison work for silverlight applications?
If yes why I'm got "System.NullReferenceException: Object reference not set to an instance of an object." for the second row
HtmlImage img = Find.ById<HtmlImage>("myImageId");
System.Drawing.Bitmap actualbmp = img.Capture();
Thanks,
Yuri
You'll need to use the Silverlight syntax instead:
ArtOfTest.WebAii.Silverlight.UI.Image img = Pages.TelerikWindowForSilverlight.SilverlightApp.Item20Image;
Assert.IsNotNull(img);
Greetings,
Anthony
the Telerik team
Thx. for answer.
What assembly I should use to get access to the TelerikWindowForSilverlight object.
Thanks,
Yuri
That is actually the name of the page I used as an example. I simply stored the image into a variable by identifying it via the Pages class. This assumes you've already added the element to the repository manually. Here is more information on how to reference an element in code in this fashion.
You'll need to use the page and element name unique to your application.
Anthony
the Telerik team
What is about Item20Image, the page does not contain this element, is it also unique for the application.
I can't find this item in Elements explorer.
I'm new in testing tool yet.
Thanks,
Yuri
That's the name of the element I'm testing in my example. It's unique to my test and won't exist in yours. You'll need to add your image element to the Elements Explorer either by recording an action/verification against it or by adding it manually from the Elements Menu with the Add To Project Elements option. Then you can reference it in code.
See this screen recording:
http://screencast.com/t/dVSRlYUehp
- I record a standard Image Verification against the Silverlight Image. (We recommend using Image Verification as a last resort as it is inherently fragile. Always use the DOM as your primary means of verification, even with images.)
- This adds a Verify step and adds the Image element to the Explorer.
- I add a coded step and use the code previously mentioned. The image is stored in a variable (img) and identified via the Pages class (Pages.PageName.SilverlightApp.ElementName).
- I ensure the SilverlightEnabled test property is True.
- I execute the test and it passes.
Regards,
Anthony
the Telerik team
I am comparing two images using
Assert.IsTrue(expected.Compare(actual, 5.0));
I was wondering how I would return the variance of the two images if it was larger than the allowed 5.0%
Using the code provided below you can get the assert passing or failing and that will be the proper behavior of the test. If you would like to get the percentage difference versus the allowed tolerance you should use a recorded verification as shown in this article.
Thank you for your understanding.
Regards,
Ivaylo
Telerik