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-184: UITestBase classes should be abstract and AssertVisualVerificationOnAllResolutions configurability #283

Merged
merged 3 commits into from
Jun 10, 2023
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion Lombiq.Tests.UI.Samples/UITestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace Lombiq.Tests.UI.Samples;

// This will be the base class for our UI test classes. Here we'll set up some common configuration. Inheriting test
// classes is not mandatory but the approach is simple and effective.
public class UITestBase : OrchardCoreUITestBase<Program>
public abstract class UITestBase : OrchardCoreUITestBase<Program>
{
protected UITestBase(ITestOutputHelper testOutputHelper)
: base(testOutputHelper)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ public static class VisualVerificationUITestContextExtensions
/// 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"/>.</param>
/// <remarks>
/// <para>
/// The parameter <c>beforeAssertAsync</c> was removed, because it sometimes polluted the stack trace, which was
Expand All @@ -49,7 +51,9 @@ public static class VisualVerificationUITestContextExtensions
public static void AssertVisualVerificationOnAllResolutions(
this UITestContext context,
IEnumerable<Size> sizes,
Func<Size, By> getSelector)
Func<Size, By> getSelector,
double pixelErrorPercentageThreshold = 0,
Action<VisualVerificationMatchApprovedConfiguration> configurator = null)
{
context.HideScrollbar();

Expand All @@ -62,9 +66,12 @@ public static void AssertVisualVerificationOnAllResolutions(
{
context.AssertVisualVerificationApproved(
getSelector(size),
pixelErrorPercentageThreshold: 0,
configurator: configuration => configuration
.WithFileNameSuffix(StringHelper.CreateInvariant($"{size.Width}x{size.Height}")));
pixelErrorPercentageThreshold: pixelErrorPercentageThreshold,
configurator: configuration =>
{
configuration.WithFileNameSuffix(StringHelper.CreateInvariant($"{size.Width}x{size.Height}"));
configurator?.Invoke(configuration);
});
}
catch (Exception exception)
{
Expand Down Expand Up @@ -92,8 +99,8 @@ public static void AssertVisualVerificationOnAllResolutions(
/// </summary>
/// <param name="context">The <see cref="UITestContext"/> in which the extension is executed on.</param>
/// <param name="pixelErrorPercentageThreshold">Maximum acceptable pixel error in percentage.</param>
/// <param name="regionOfInterest">Region of interest. Can be null.</param>
/// <param name="configurator">Action callback to configure the behavior. Can be null.</param>
/// <param name="regionOfInterest">Region of interest. Can be <see langword="null"/>.</param>
/// <param name="configurator">Action callback to configure the behavior. Can be <see langword="null"/>.</param>
/// <exception cref="VisualVerificationBaselineImageNotFoundException">
/// If no baseline image found under project path.
/// </exception>
Expand All @@ -118,8 +125,8 @@ public static void AssertVisualVerificationApproved(
/// <param name="context">The <see cref="UITestContext"/> in which the extension is executed on.</param>
/// <param name="elementSelector">Selector for the target element.</param>
/// <param name="pixelErrorPercentageThreshold">Maximum acceptable pixel error in percentage.</param>
/// <param name="regionOfInterest">Region of interest. Can be null.</param>
/// <param name="configurator">Action callback to configure the behavior. Can be null.</param>
/// <param name="regionOfInterest">Region of interest. Can be <see langword="null"/>.</param>
/// <param name="configurator">Action callback to configure the behavior. Can be <see langword="null"/>.</param>
/// <exception cref="VisualVerificationBaselineImageNotFoundException">
/// If no baseline image found under project path.
/// </exception>
Expand Down Expand Up @@ -167,8 +174,8 @@ public static void AssertVisualVerificationApproved(
/// <param name="context">The <see cref="UITestContext"/> in which the extension is executed on.</param>
/// <param name="element">Target element.</param>
/// <param name="pixelErrorPercentageThreshold">Maximum acceptable pixel error in percentage.</param>
/// <param name="regionOfInterest">Region of interest. Can be null.</param>
/// <param name="configurator">Action callback to configure the behavior. Can be null.</param>
/// <param name="regionOfInterest">Region of interest. Can be <see langword="null"/>.</param>
/// <param name="configurator">Action callback to configure the behavior. Can be <see langword="null"/>.</param>
/// <exception cref="VisualVerificationBaselineImageNotFoundException">
/// If no baseline image found under project path.
/// </exception>
Expand Down Expand Up @@ -199,8 +206,8 @@ public static void AssertVisualVerificationApproved(
/// <param name="context">The <see cref="UITestContext"/> in which the extension is executed on.</param>
/// <param name="baseline">The baseline image.</param>
/// <param name="pixelErrorPercentageThreshold">Maximum acceptable pixel error in percentage.</param>
/// <param name="regionOfInterest">Region of interest. Can be null.</param>
/// <param name="configurator">Action callback to configure the behavior. Can be null.</param>
/// <param name="regionOfInterest">Region of interest. Can be <see langword="null"/>.</param>
/// <param name="configurator">Action callback to configure the behavior. Can be <see langword="null"/>.</param>
public static void AssertVisualVerification(
this UITestContext context,
Image baseline,
Expand All @@ -222,8 +229,8 @@ public static void AssertVisualVerification(
/// <param name="elementSelector">Selector for the target element.</param>
/// <param name="baseline">The baseline image.</param>
/// <param name="pixelErrorPercentageThreshold">Maximum acceptable pixel error in percentage.</param>
/// <param name="regionOfInterest">Region of interest. Can be null.</param>
/// <param name="configurator">Action callback to configure the behavior. Can be null.</param>
/// <param name="regionOfInterest">Region of interest. Can be <see langword="null"/>.</param>
/// <param name="configurator">Action callback to configure the behavior. Can be <see langword="null"/>.</param>
public static void AssertVisualVerification(
this UITestContext context,
By elementSelector,
Expand Down Expand Up @@ -270,8 +277,8 @@ public static void AssertVisualVerification(
/// <param name="element">The target element.</param>
/// <param name="baseline">The baseline image.</param>
/// <param name="pixelErrorPercentageThreshold">Maximum acceptable pixel error in percentage.</param>
/// <param name="regionOfInterest">Region of interest. Can be null.</param>
/// <param name="configurator">Action callback to configure the behavior. Can be null.</param>
/// <param name="regionOfInterest">Region of interest. Can be <see langword="null"/>.</param>
/// <param name="configurator">Action callback to configure the behavior. Can be <see langword="null"/>.</param>
public static void AssertVisualVerification(
this UITestContext context,
IWebElement element,
Expand Down