0
我使用webdriver的與C#,這個問題是的webdriver無法測試設計,所以我試圖製造類似截圖對比,是因爲我在大工地一位工作一天,它具有新的期貨,新的變化,所以我不知道在哪裏或哪個瀏覽器的設計並沒有爆發。 我的問題是你知道的任何工具,框架,項目或一些想法?自動化測試畫面比較
我已經寫了一些東西,但它不是很完美,我的代碼在不同的瀏覽器和版本上對網站進行截圖,之後它將它們剪切並與演示屏幕進行比較。如果有超過5%的錯誤像素測試正在下降。
P.S.我是一個初中)
我的一些代碼,如果有人需要它的未來:
var screenshot = ((ITakesScreenshot)Global.Driver).GetScreenshot(); screenshot.SaveAsFile(dirHomePage + "homepage.png", ImageFormat.Png); var mainImg = new Bitmap(File.OpenRead(dirHomePage + "homepage.png")); var section = new Rectangle(new Point(0, 0), new Size(mainImg.Width, 153)); this.header = this.CropImage(mainImg, section); this.header = this.ClearImage(this.header, Color.White, 264, mainImg.Width, 30, 60); ImageComparison(this.header, this.demoHeader);
public Bitmap ClearImage(Bitmap source, Color color, int fromW, int toW, int fromH, int toH)
{
Bitmap bmp = source;
for (int i = fromW; i < toW; i++)
{
for (int j = fromH; j < toH; j++)
{
bmp.SetPixel(i, j, color);
}
}
return bmp;
}
public Bitmap CropImage(Bitmap source, Rectangle section)
{
Bitmap bmp = new Bitmap(section.Width, section.Height);
Graphics g = Graphics.FromImage(bmp);
g.DrawImage(source, 0, 0, section, GraphicsUnit.Pixel);
return bmp;
}
public void ImageComparison(Bitmap firstImg, Bitmap secondImg)
{
bool match = false;
int nrBadPixels = 0;
if (firstImg.Width.Equals(secondImg.Width) && firstImg.Height.Equals(secondImg.Height))
{
double acceptedProcent = (firstImg.Width * firstImg.Height) * 0.05;
for (int i = 0; i < firstImg.Width; i++)
{
for (int j = 0; j < firstImg.Height; j++)
{
string firstImgRef = firstImg.GetPixel(i, j).ToString();
string secondImgRef = secondImg.GetPixel(i, j).ToString();
if (firstImgRef != secondImgRef)
{
nrBadPixels++;
if (nrBadPixels > acceptedProcent)
{
match = false;
break;
}
match = true;
}
}
}
}
Assert.IsTrue(match);
}
SikuliWebDriver其爲Java =(我需要C# –