コード例 #1
0
ファイル: FrontendTests.cs プロジェクト: gnilesh4/squidex
        public async Task Should_render_properly(string name, string url)
        {
            using (var browserFetcher = new BrowserFetcher())
            {
                await browserFetcher.DownloadAsync();
            }

            await using var browser = await Puppeteer.LaunchAsync(new LaunchOptions
            {
                Headless        = true,
                DefaultViewport = new ViewPortOptions
                {
                    Height      = 800,
                    IsLandscape = true,
                    IsMobile    = false,
                    Width       = 1000
                },
                Args = new string[]
                {
                    "--no-sandbox"
                }
            });

            await using var page = await browser.NewPageAsync();

            await page.GoToAsync(_.ClientManager.Options.Url + url + "?skip-setup");

            await page.ScreenshotAsync($"__{name}.jpg");

            var diff = ImageSharpCompare.CalcDiff($"__{name}.jpg", $"Assets/{name}.jpg");

            Assert.InRange(diff.MeanError, 0, 10);
        }
コード例 #2
0
        public void ShouldVerifyThatImagesAreSemiEqual(string pathPic1, string pathPic2, int expectedMeanError, int expectedAbsoluteError, int expectedPixelErrorCount, double expectedPixelErrorPercentage)
        {
            var diff = ImageSharpCompare.CalcDiff(pathPic1, pathPic2);

            Assert.That(diff.AbsoluteError, Is.EqualTo(expectedAbsoluteError), "AbsoluteError");
            Assert.That(diff.MeanError, Is.EqualTo(expectedMeanError), "MeanError");
            Assert.That(diff.PixelErrorCount, Is.EqualTo(expectedPixelErrorCount), "PixelErrorCount");
            Assert.That(diff.PixelErrorPercentage, Is.EqualTo(expectedPixelErrorPercentage), "PixelErrorPercentage");
        }
コード例 #3
0
        public void ShouldVerifyThatImageStreamsAreSemiEqual(string pathPic1, string pathPic2, int expectedAbsoluteError, double expectedMeanError, int expectedPixelErrorCount, double expectedPixelErrorPercentage)
        {
            using var pic1 = new FileStream(pathPic1, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
            using var pic2 = new FileStream(pathPic2, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);

            var diff = ImageSharpCompare.CalcDiff(pic1, pic2);

            Assert.That(diff.AbsoluteError, Is.EqualTo(expectedAbsoluteError), "AbsoluteError");
            Assert.That(diff.MeanError, Is.EqualTo(expectedMeanError), "MeanError");
            Assert.That(diff.PixelErrorCount, Is.EqualTo(expectedPixelErrorCount), "PixelErrorCount");
            Assert.That(diff.PixelErrorPercentage, Is.EqualTo(expectedPixelErrorPercentage), "PixelErrorPercentage");
        }
コード例 #4
0
        public void Diffmask(string pathPic1, string pathPic2, int expectedMeanError, int expectedAbsoluteError, int expectedPixelErrorCount, double expectedPixelErrorPercentage)
        {
            using (var fileStreamDifferenceMask = File.Create("differenceMask.png"))
                using (var maskImage = ImageSharpCompare.CalcDiffMaskImage(pathPic1, pathPic2))
                {
                    SixLabors.ImageSharp.ImageExtensions.SaveAsPng(maskImage, fileStreamDifferenceMask);
                }

            var maskedDiff = ImageSharpCompare.CalcDiff(pathPic1, pathPic2, "differenceMask.png");

            Assert.That(maskedDiff.AbsoluteError, Is.EqualTo(expectedAbsoluteError), "AbsoluteError");
            Assert.That(maskedDiff.MeanError, Is.EqualTo(expectedMeanError), "MeanError");
            Assert.That(maskedDiff.PixelErrorCount, Is.EqualTo(expectedPixelErrorCount), "PixelErrorCount");
            Assert.That(maskedDiff.PixelErrorPercentage, Is.EqualTo(expectedPixelErrorPercentage), "PixelErrorPercentage");
        }
コード例 #5
0
        public void DiffmaskSteams(string pathPic1, string pathPic2, int expectedMeanError, int expectedAbsoluteError, int expectedPixelErrorCount, double expectedPixelErrorPercentage)
        {
            using var pic1 = new FileStream(pathPic1, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
            using var pic2 = new FileStream(pathPic2, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);

            using var maskImage = ImageSharpCompare.CalcDiffMaskImage(pic1, pic2);

            pic1.Position = 0;
            pic2.Position = 0;

            var maskedDiff = ImageSharpCompare.CalcDiff(pic1, pic2, maskImage);

            Assert.That(maskedDiff.AbsoluteError, Is.EqualTo(expectedAbsoluteError), "AbsoluteError");
            Assert.That(maskedDiff.MeanError, Is.EqualTo(expectedMeanError), "MeanError");
            Assert.That(maskedDiff.PixelErrorCount, Is.EqualTo(expectedPixelErrorCount), "PixelErrorCount");
            Assert.That(maskedDiff.PixelErrorPercentage, Is.EqualTo(expectedPixelErrorPercentage), "PixelErrorPercentage");
        }
コード例 #6
0
    public static void AssertImagesEqual <TPixel>(Image <TPixel> actualImage,
                                                  string referenceName) where TPixel : unmanaged, IPixel <TPixel>
    {
        var imageBasename = TestContext.CurrentContext.Test.FullName.Replace("OpenTemple.Tests.", "")
                            + Path.GetFileNameWithoutExtension(referenceName);
        var actualPath = imageBasename + "_actual.png";

        actualImage.Save(actualPath);

        var expectedPath = TestData.GetPath(referenceName);

        if (!File.Exists(expectedPath))
        {
            File.Copy(actualPath, expectedPath);
            throw new NUnitException("Reference file didn't exist: " + expectedPath
                                     + " copied actual to its location");
        }

        using var expectedImage   = Image.Load(expectedPath);
        using var expectedImage32 = expectedImage.CloneAs <Rgba32>();
        using var actualImage32   = actualImage.CloneAs <Rgba32>();

        var imageDiff = ImageSharpCompare.CalcDiff(actualImage32, expectedImage32);

        if (imageDiff.PixelErrorCount > 0)
        {
            // Re-save the expected image so it is next to the actual and difference
            File.Delete(imageBasename + "_expected.png");
            File.Copy(expectedPath, imageBasename + "_expected.png");

            // Calculate the difference as an image
            var visualDifference = imageBasename + "_difference.png";
            using (var maskImage = ImageSharpCompare.CalcDiffMaskImage(actualImage32, expectedImage32))
                maskImage.SaveAsPng(visualDifference);

            TestContext.AddTestAttachment(actualPath, "Actual image");
            TestContext.AddTestAttachment(imageBasename + "_expected.png", "Expected image");
            TestContext.AddTestAttachment(visualDifference, "Visual difference");
            Assert.AreEqual(0, imageDiff.PixelErrorCount, "Images are different, see "
                            + actualPath + " and " + visualDifference);
        }
    }