Skip to content

Commit

Permalink
Merge pull request #369 from Lombiq/issue/LMBQ-323
Browse files Browse the repository at this point in the history
LMBQ-323: Adding AssertVisualVerificationApprovedOnAllResolutionsWithPlatformSuffix
  • Loading branch information
MZole authored May 13, 2024
2 parents 798b78a + 7013ff9 commit 45cb69c
Showing 1 changed file with 35 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ public static void AssertVisualVerificationOnAllResolutions(
IEnumerable<Size> sizes,
Func<Size, By> getSelector,
double pixelErrorPercentageThreshold = 0,
bool checkOS = false,
Action<VisualVerificationMatchApprovedConfiguration> configurator = null)
{
context.HideScrollbar();
Expand All @@ -70,16 +69,7 @@ public static void AssertVisualVerificationOnAllResolutions(
pixelErrorPercentageThreshold: pixelErrorPercentageThreshold,
configurator: configuration =>
{
var fileNameSuffix = StringHelper.CreateInvariant($"{size.Width}x{size.Height}");
if (checkOS)
{
var oS = OperatingSystem.IsWindows() ? "Windows" : "Unix";
fileNameSuffix = $"{fileNameSuffix}-{oS}";
}
configuration.WithFileNameSuffix(fileNameSuffix);
configuration.WithFileNameSuffix(StringHelper.CreateInvariant($"{size.Width}x{size.Height}"));
configurator?.Invoke(configuration);
});
}
Expand All @@ -103,6 +93,40 @@ public static void AssertVisualVerificationOnAllResolutions(
context.RestoreHiddenScrollbar();
}

/// <summary>
/// Compares the baseline image and screenshot of the selected element on multiple different resolutions, based on
/// the operating system's platform.
/// </summary>
/// <param name="sizes">The comparison is performed on each of these resolutions.</param>
/// <param name="getSelector">
/// Returns the selector for the given screen size. This may return the same selector all the time, or a different
/// selector, e.g. if mobile and desktop views have different DOMs.
/// </param>
/// <param name="pixelErrorPercentageThreshold">Maximum acceptable pixel error in percentage.</param>
/// <param name="configurator">Action callback to configure the behavior. Can be <see langword="null"/>, but in the
/// method we are always using <see
/// cref="VisualVerificationMatchApprovedConfiguration.WithUsePlatformAsSuffix()"/>.</param>
/// <remarks>
/// <para>
/// The parameter <c>beforeAssertAsync</c> was removed, because it sometimes polluted the stack trace, which was
/// used in visual verification tests, so it caused tests to fail. The point of <c>beforeAssertAsync</c> was, that
/// sometimes the page can change on the resize window event. So the navigation happening after the window resize
/// ensures that the currently loaded page only existed with the desired screen size.
/// </para>
/// </remarks>
[VisualVerificationApprovedMethod]
public static void AssertVisualVerificationApprovedOnAllResolutionsWithPlatformSuffix(
this UITestContext context,
IEnumerable<Size> sizes,
Func<Size, By> getSelector,
double pixelErrorPercentageThreshold = 0,
Action<VisualVerificationMatchApprovedConfiguration> configurator = null) =>
context.AssertVisualVerificationOnAllResolutions(
sizes,
getSelector,
pixelErrorPercentageThreshold,
configuration => configuration.WithUsePlatformAsSuffix());

/// <summary>
/// Compares the baseline image and screenshot of the whole page.
/// <see cref="AssertVisualVerificationApproved(UITestContext, By, double, Rectangle?, Action{VisualVerificationMatchApprovedConfiguration})"/>.
Expand Down

0 comments on commit 45cb69c

Please sign in to comment.