From eda97e622c6339258bfa3348005a539c3d210dc9 Mon Sep 17 00:00:00 2001 From: Aliaksej Mialeshka Date: Fri, 30 Aug 2024 17:56:45 +0200 Subject: [PATCH] Stabilize ImageComparatorTests --- .../Visualization/ImageComparatorTests.cs | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/Aquality.Selenium.Core/tests/Aquality.Selenium.Core.Tests/Visualization/ImageComparatorTests.cs b/Aquality.Selenium.Core/tests/Aquality.Selenium.Core.Tests/Visualization/ImageComparatorTests.cs index 601bd0d..75ad5d6 100644 --- a/Aquality.Selenium.Core/tests/Aquality.Selenium.Core.Tests/Visualization/ImageComparatorTests.cs +++ b/Aquality.Selenium.Core/tests/Aquality.Selenium.Core.Tests/Visualization/ImageComparatorTests.cs @@ -7,6 +7,9 @@ using NUnit.Framework; using OpenQA.Selenium; using System; +using Aquality.Selenium.Core.Utilities; +using SkiaSharp; +using System.Collections.Generic; namespace Aquality.Selenium.Core.Tests.Visualization { @@ -66,10 +69,16 @@ public void Should_BePossibleTo_GetPercentageDifference_ForDifferentElements_Wit [Test] public void Should_BePossibleTo_GetPercentageDifference_ForSimilarElements() { - StartLoading(); - var firstImage = LoadingLabel.GetElement().GetScreenshot().AsImage(); - AqualityServices.ServiceProvider.GetRequiredService().WaitFor(() => firstImage.Height < LoadingLabel.Visual.Size.Height); - var secondImage = LoadingLabel.GetElement().GetScreenshot().AsImage(); + SKImage firstImage = null, secondImage = null; + AqualityServices.ServiceProvider.GetRequiredService().DoWithRetry(() => + { + AqualityServices.Application.Driver.Navigate().Refresh(); + StartLoading(); + firstImage = LoadingLabel.GetElement().GetScreenshot().AsImage(); + AqualityServices.ServiceProvider.GetRequiredService().WaitFor(() => firstImage.Height < LoadingLabel.Visual.Size.Height); + secondImage = LoadingLabel.GetElement().GetScreenshot().AsImage(); + }, new List { typeof(WebDriverException)}); + Assert.Multiple(() => { Assert.That(ImageComparator.PercentageDifference(firstImage, secondImage, threshold: 0), Is.Not.EqualTo(0));