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

OSOE-591: Test doesn't fail if the visual verification baseline image is not found but the test is retried #298

Merged
merged 5 commits into from
Jul 27, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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
@@ -1,4 +1,5 @@
using System;
using System.Globalization;

namespace Lombiq.Tests.UI.Exceptions;

Expand All @@ -7,14 +8,22 @@ namespace Lombiq.Tests.UI.Exceptions;
public class VisualVerificationBaselineImageNotFoundException : Exception
#pragma warning restore CA1032 // Implement standard exception constructors
{
public VisualVerificationBaselineImageNotFoundException(string path, Exception innerException = null)
: base(
$"Baseline image file not found, thus it was created automatically under the path {path}."
public VisualVerificationBaselineImageNotFoundException(
string path,
int maxRetryCount,
Exception innerException = null)
: base(GetExceptionMessage(path, maxRetryCount), innerException)
{
}

private static string GetExceptionMessage(string path, int maxRetryCount) =>
maxRetryCount == 0 ? $"Baseline image file not found, thus it was created automatically under the path {path}."
+ " Please set its \"Build action\" to \"Embedded resource\" if you want to deploy a self-contained"
+ " (like a NuGet package) UI testing assembly. If you run the test again, this newly created verification"
+ " file will be asserted against and the assertion will pass (unless the display of the app changed in the"
+ " meantime).",
innerException)
{
}
+ " meantime)."
: string.Create(
DemeSzabolcs marked this conversation as resolved.
Show resolved Hide resolved
CultureInfo.InvariantCulture,
$"Baseline image file was not found under the path {path} and MaxRetryCount is set to {maxRetryCount}, "
MZole marked this conversation as resolved.
Show resolved Hide resolved
+ $"so it won't be generated.");
}
Original file line number Diff line number Diff line change
Expand Up @@ -389,8 +389,18 @@ private static void AssertVisualVerificationApproved(

if (!File.Exists(approvedContext.BaselineImagePath))
{
context.SaveSuggestedImage(element, approvedContext.BaselineImagePath, approvedContext.BaselineImageFileName);
throw new VisualVerificationBaselineImageNotFoundException(approvedContext.BaselineImagePath);
if (context.Configuration.MaxRetryCount == 0)
{
context.SaveSuggestedImage(
element,
approvedContext.BaselineImagePath,
approvedContext.BaselineImageFileName);
throw new VisualVerificationBaselineImageNotFoundException(
approvedContext.BaselineImagePath, context.Configuration.MaxRetryCount);
DemeSzabolcs marked this conversation as resolved.
Show resolved Hide resolved
}

throw new VisualVerificationBaselineImageNotFoundException(
approvedContext.BaselineImagePath, context.Configuration.MaxRetryCount);
}

baselineImage = Image.Load(approvedContext.BaselineImagePath);
Expand Down