Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LMBQ-323: Adding AssertVisualVerificationApprovedOnAllResolutionsWithPlatformSuffix #369

Merged
merged 4 commits into from
May 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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