public void ShouldTakeAndCompareScreenshot(string exampleName) { var fragmentBitmap = GetFragmentScreenshot(exampleName); var expectedBitmap = VisualTestHelpers.LoadFromPng(Path.Combine(ExpectationsPath, GetDeviceId(_app), $"{exampleName}.png")); VisualTestHelpers.CompareBitmaps(exampleName, fragmentBitmap, expectedBitmap); }
private Bitmap GetFragmentScreenshot(string exampleName) { var actualScreenshotFileInfo = TakeScreenshotOfExample(exampleName); var rect = _app.Query(c => c.Marked("fragment_container")).FirstOrDefault()?.Rect; if (rect == null) { throw new InvalidOperationException("fragment_container has null rect"); } var actualBitmap = VisualTestHelpers.LoadFromPng(actualScreenshotFileInfo.FullName); var fragmentRect = new Rectangle((int)rect.X, (int)rect.Y, (int)rect.Width, (int)rect.Height); var fragmentBitmap = new Bitmap(fragmentRect.Width, fragmentRect.Height); using (var graphics = Graphics.FromImage(fragmentBitmap)) { graphics.DrawImage(actualBitmap, 0, 0, fragmentRect, GraphicsUnit.Pixel); } return(fragmentBitmap); }
public void UpdateScreenshotsWithExpectations(string exampleName) { var fragmentBitmap = GetFragmentScreenshot(exampleName); VisualTestHelpers.SaveToPng(Path.Combine(ExpectationsPath, GetDeviceId(_app), $"{exampleName}.png"), fragmentBitmap); }