Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
        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);
        }
Ejemplo n.º 3
0
        public void UpdateScreenshotsWithExpectations(string exampleName)
        {
            var fragmentBitmap = GetFragmentScreenshot(exampleName);

            VisualTestHelpers.SaveToPng(Path.Combine(ExpectationsPath, GetDeviceId(_app), $"{exampleName}.png"), fragmentBitmap);
        }