Skip to content

Commit

Permalink
Stabilize ImageComparatorTests
Browse files Browse the repository at this point in the history
  • Loading branch information
mialeska committed Aug 30, 2024
1 parent d28171d commit eda97e6
Showing 1 changed file with 13 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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<IConditionalWait>().WaitFor(() => firstImage.Height < LoadingLabel.Visual.Size.Height);
var secondImage = LoadingLabel.GetElement().GetScreenshot().AsImage();
SKImage firstImage = null, secondImage = null;
AqualityServices.ServiceProvider.GetRequiredService<IActionRetrier>().DoWithRetry(() =>
{
AqualityServices.Application.Driver.Navigate().Refresh();
StartLoading();
firstImage = LoadingLabel.GetElement().GetScreenshot().AsImage();
AqualityServices.ServiceProvider.GetRequiredService<IConditionalWait>().WaitFor(() => firstImage.Height < LoadingLabel.Visual.Size.Height);
secondImage = LoadingLabel.GetElement().GetScreenshot().AsImage();
}, new List<Type> { typeof(WebDriverException)});

Assert.Multiple(() =>
{
Assert.That(ImageComparator.PercentageDifference(firstImage, secondImage, threshold: 0), Is.Not.EqualTo(0));
Expand Down

0 comments on commit eda97e6

Please sign in to comment.