実際、Selenium の隠された利点の 1 つは、それを使用してブラウザーのスクリーン キャプチャを取得できることです。次に、 C# を使用してイメージ間の違いを見つけるで説明されている手法を使用して、以前のスナップショット間の違いを強調表示できます。
この例では、ホームページのスクリーンショットを取得して差分画像を作成する方法を示します。少し手を加えるだけで、同じ手法を使用して、異なるピクセルをカウントできます。
[Test]
public void CompareHomePageToPrevious()
{
string fileName = Path.Combine(Environment.CurrentDirectory, "homepage.bmp");
var selenium = new DefaultSelenium("localhost", 4444, "*chrome", "http://mywebsite");
selenium.Start();
selenium.Open("/");
selenium.CaptureEntirePageScreenshot(fileName, "");
// Load current and previous captures
var current = new Bitmap(filename);
var previous = new Bitmap(_previousHomepageImage);
// Find all pixels that are the same and make them pink
Bitmap diff = ImageTool.GetDifferenceImage(current,previous,Color.Pink);
diff.MakeTransparent(Color.Pink);
// Save the image for viewing
// or count the number of different
}
Selenium は、クロスプラットフォームかつクロスブラウザーであるため、非常に興味深い選択肢です。つまり、さまざまなブラウザーの画面をキャプチャできます。この手法を使用して、ビルド間でスナップショットを比較したり、ブラウザー間で比較したりできます。