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

Image comparison

9 Answers 156 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Waylon
Top achievements
Rank 1
Waylon asked on 02 Jun 2011, 04:23 PM
Hi There,

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

Sort by
0
Anthony
Telerik team
answered on 02 Jun 2011, 05:13 PM
Hello Waylon,

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 >>

0
Yuri Brutyan
Top achievements
Rank 1
answered on 25 Nov 2011, 10:22 AM
Hi There,

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
0
Anthony
Telerik team
answered on 28 Nov 2011, 10:02 PM
Hello Yuri Brutyan,

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
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Yuri Brutyan
Top achievements
Rank 1
answered on 08 Dec 2011, 03:37 PM
Hello Anthony,
Thx. for answer.

What assembly I should use to get access to the TelerikWindowForSilverlight object.

Thanks,
Yuri
0
Anthony
Telerik team
answered on 08 Dec 2011, 04:39 PM
Hi Yuri Brutyan,

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.

Greetings,
Anthony
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Yuri Brutyan
Top achievements
Rank 1
answered on 09 Dec 2011, 10:24 AM
Hi Anthony,

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
0
Anthony
Telerik team
answered on 09 Dec 2011, 05:31 PM
Hi Yuri Brutyan,

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

  1. 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.)
  2. This adds a Verify step and adds the Image element to the Explorer.
  3. 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).
  4. I ensure the SilverlightEnabled test property is True.
  5. I execute the test and it passes.

Regards,
Anthony
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Reese
Top achievements
Rank 1
answered on 16 May 2014, 06:28 PM
Hey there,

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%
0
Ivaylo
Telerik team
answered on 21 May 2014, 12:22 PM
Hello Reese,

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
 
The New Release of Telerik Test Studio Is Here! Download, install,
and send us your feedback!
Tags
General Discussions
Asked by
Waylon
Top achievements
Rank 1
Answers by
Anthony
Telerik team
Yuri Brutyan
Top achievements
Rank 1
Reese
Top achievements
Rank 1
Ivaylo
Telerik team
Share this question
or