In order to perform visual tests under Selenium, I performed the image comparison tests ( 2 images only). I use the file size to see if there is a difference or not. However, nothing tells me where I have this difference and I would like to be able to display the difference(s) shown on the image.
I was thinking of a comparison by color instead of size. It seems complex to me especially since I would like to have an image output showing the difference (with a crop that specifies the area) or by extracting the pixels impacted by this difference. Do you think it's possible to do it under selenium in C#? For the moment, i tried by size.
public static void TestComapre()
{
string imgPath1 = <//PATHNAME >
string imgPath2 = <//PATHNAME >
const int size = 1000;
var len = new FileInfo(imgPath1).Length;
if (len != new FileInfo(imgPath2).Length)
var s1 = File.OpenRead(imgPath1);
var s2 = File.OpenRead(imgPath2);
var buf1 = new byte[size];
var buf2 = new byte[size];
for (int i = 0; i < len / size; i++)
{
s1.Read(buf1, 0, size);
s2.Read(buf2, 0, size);
if (CompareBuffers(buf1, buf2) == false)
Assert.Fail();
}
Assert.True(true);
}