Skip to content

Commit

Permalink
Add stacktraces to the failure dump for investigation
Browse files Browse the repository at this point in the history
  • Loading branch information
Oliver Friedrich committed Jan 9, 2023
1 parent f642da2 commit 97915ee
Showing 1 changed file with 26 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using SixLabors.ImageSharp.Formats.Png;
using SixLabors.ImageSharp.Processing;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
Expand All @@ -23,6 +24,7 @@ namespace Lombiq.Tests.UI.Extensions;
public static class VisualVerificationUITestContextExtensions
{
private const string ConditionLessThenOrEqualTo = "less than or equal to";

private const string HintFailureDumpItemAlreadyExists = $@"
Hint: You can use the configurator callback of {nameof(AssertVisualVerificationApproved)} and {nameof(AssertVisualVerification)}
to customize the name of the dump item.";
Expand Down Expand Up @@ -188,11 +190,10 @@ public static void AssertVisualVerification(
configurator?.Invoke(configuration);
configuration.WithFileNameSuffix(
new[]
{
elementSelector.ToString().MakeFileSystemFriendly(),
configuration.FileNameSuffix,
}
.JoinNotNullOrEmpty("-")
{
elementSelector.ToString().MakeFileSystemFriendly(), configuration.FileNameSuffix,
}
.JoinNotNullOrEmpty("-")
);
});

Expand Down Expand Up @@ -249,11 +250,10 @@ private static void AssertVisualVerificationApproved(
configurator?.Invoke(configuration);
configuration.WithFileNameSuffix(
new[]
{
elementSelector.ToString().MakeFileSystemFriendly(),
configuration.FileNameSuffix,
}
.JoinNotNullOrEmpty("-")
{
elementSelector.ToString().MakeFileSystemFriendly(), configuration.FileNameSuffix,
}
.JoinNotNullOrEmpty("-")
);
});

Expand All @@ -271,8 +271,22 @@ private static void AssertVisualVerificationApproved(
var stackTrace = new EnhancedStackTrace(new StackTrace(fNeedFileInfo: true))
.Where(frame => frame.GetMethodBase() != null && !IsCompilerGenerated(frame))
.ToList();
var testFrame = stackTrace
.FirstOrDefault(frame => !IsVisualVerificationMethod(frame));

context.AppendFailureDump(
Path.Combine(VisualVerificationMatchNames.DumpFolderName, configuration.WrapFileName("stacktrace-base.txt")),
content: stackTrace.ToString());

var nonVisualVerificationMethodFrames = stackTrace
.Where(frame => !IsVisualVerificationMethod(frame))
.ToList();

context.AppendFailureDump(
Path.Combine(VisualVerificationMatchNames.DumpFolderName, configuration.WrapFileName("stacktrace-filtered.txt")),
content: nonVisualVerificationMethodFrames
.Select(frame => frame.ToString())
.JoinNotNullOrEmpty(Environment.NewLine));

var testFrame = nonVisualVerificationMethodFrames.FirstOrDefault();

if (testFrame != null && configuration.StackOffset > 0)
{
Expand Down

0 comments on commit 97915ee

Please sign in to comment.