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-532: Fixing NRE when running visual verification tests from binaries #255

Merged
merged 3 commits into from
Jan 15, 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
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ private static void AssertVisualVerificationApproved(
.MethodInfo
.DeclaringType?
.Assembly
.GetResourceImageSharpImage(approvedContext.BaselineResourceName);
.GetResourceImageSharpImage(approvedContext.BaselineImageResourceName);

if (baselineImage == null)
{
Expand All @@ -305,7 +305,7 @@ private static void AssertVisualVerificationApproved(
{
using var suggestedImage = context.TakeElementScreenshot(element);

var suggestedImageFileName = $"{approvedContext.BaselineFileName}.png";
var suggestedImageFileName = $"{approvedContext.BaselineImageFileName}.png";

context.AppendFailureDump(
Path.Combine(
Expand All @@ -322,7 +322,7 @@ private static void AssertVisualVerificationApproved(

if (!File.Exists(approvedContext.BaselineImagePath))
{
context.SaveSuggestedImage(element, approvedContext.BaselineImagePath, approvedContext.BaselineFileName);
context.SaveSuggestedImage(element, approvedContext.BaselineImagePath, approvedContext.BaselineImageFileName);
throw new VisualVerificationBaselineImageNotFoundException(approvedContext.BaselineImagePath);
}

Expand All @@ -336,7 +336,7 @@ private static void AssertVisualVerificationApproved(
baselineImage,
diff => comparator(approvedContext, diff),
regionOfInterest,
cfg => cfg.WithFileNamePrefix(approvedContext.BaselineFileName)
cfg => cfg.WithFileNamePrefix(approvedContext.BaselineImageFileName)
.WithFileNameSuffix(string.Empty));
}
finally
Expand Down Expand Up @@ -608,9 +608,9 @@ private static string FormatAssertionMessage<TValue>(
{
loadedFrom = $"file: {approvedContext.BaselineImagePath}";
}
else if (!string.IsNullOrEmpty(approvedContext.BaselineResourceName))
else if (!string.IsNullOrEmpty(approvedContext.BaselineImageResourceName))
{
loadedFrom = $"embedded resource: {approvedContext.BaselineResourceName}";
loadedFrom = $"embedded resource: {approvedContext.BaselineImageResourceName}";
}

if (!string.IsNullOrEmpty(loadedFrom))
Expand Down
22 changes: 15 additions & 7 deletions Lombiq.Tests.UI/Models/VisualVerificationMatchApprovedContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,14 @@ public class VisualVerificationMatchApprovedContext
public string ModuleName { get; }
public string MethodName { get; }
public string BrowserName { get; }
public string BaselineFileName { get; }
public string BaselineResourceName { get; }
public string ModuleDirectory { get; }
public string BaselineImageFileName { get; }
public string BaselineImageResourceName { get; }

/// <summary>
/// Gets the local file system path of the baseline image. Will be <see langword="null"/> if the test is not loaded
/// from source but binaries; load the image from embedded resources then instead, see <see
/// cref="BaselineImageResourceName"/>.
/// </summary>
public string BaselineImagePath { get; }

public VisualVerificationMatchApprovedContext(
Expand All @@ -26,11 +31,14 @@ public VisualVerificationMatchApprovedContext(
MethodName = GetMethodName(testFrame);
BrowserName = context.Driver.As<IHasCapabilities>().Capabilities.GetCapability("browserName") as string;

BaselineFileName = configuration.BaselineFileNameFormatter(configuration, this);
BaselineResourceName = $"{testFrame.MethodInfo.DeclaringType!.Namespace}.{BaselineFileName}.png";
BaselineImageFileName = configuration.BaselineFileNameFormatter(configuration, this);
BaselineImageResourceName = $"{testFrame.MethodInfo.DeclaringType!.Namespace}.{BaselineImageFileName}.png";

ModuleDirectory = Path.GetDirectoryName(testFrame.GetFileName());
BaselineImagePath = Path.Combine(ModuleDirectory!, $"{BaselineFileName}.png");
var testSourceDirectoryPath = Path.GetDirectoryName(testFrame.GetFileName());
if (!string.IsNullOrEmpty(testSourceDirectoryPath))
{
BaselineImagePath = Path.Combine(testSourceDirectoryPath!, $"{BaselineImageFileName}.png");
}
}

private static string GetModuleName(EnhancedStackFrame frame)
Expand Down