Unfortunately we dont have Assert. AreEqual for images, available in MStest (correct me if I'm wrong).
While performing automation using C#, we have to compare two images downloaded from target website and images stored at some shared location. To verify this we don't have standard assert provided by MStest.
Then we thought to write our own assert class for images. Which will compare the images and based on condition it will assert. Now it's time to share with all automation community.
So here is the piece of code to perform this.
First of all I will write Test Method which will compare two images with assert.
using System;
using System.Drawing;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using AssertImage;
namespace TestAssertImage
{
[TestClass]
public class UnitTest1
{
[TestMethod]
public void TestImagesEqual()
{
const string imageLocation1 = @"C:\Users\xmdj\Desktop\Images Of Talk2DB\Connect.PNG";
const string imageLocation2 = @"C:\Users\xmdj\Desktop\Images Of Talk2DB\Connect1.PNG";
var bitmapExpected = new Bitmap(imageLocation1, true);
var bitmapActual = new Bitmap(imageLocation2, true);
Assert.IsNotNull(bitmapExpected, "Not Null");
Assert.IsNotNull(bitmapActual, "Not Null");
AssertImage.AssertImage.AreEqual(bitmapExpected, bitmapActual, "Not Same!!");
}
}
}
The highlighted part in above code is our extension to assert for images.
And below is our extension class for AssertImage.AreEqual.
using System.Drawing;
using System.Security.Cryptography;
using Microsoft.VisualStudio.TestTools.UnitTesting;

Manoj Singh PanwarPosted Dec 6, 2011, 12:22 PM
Mr Jawed.. Keep teaching new things. Thanks for sharing.