From 97915eee020afc22d47478c243a36046fe803f6c Mon Sep 17 00:00:00 2001 From: Oliver Friedrich Date: Mon, 9 Jan 2023 12:17:35 +0100 Subject: [PATCH] Add stacktraces to the failure dump for investigation --- ...sualVerificationUITestContextExtensions.cs | 38 +++++++++++++------ 1 file changed, 26 insertions(+), 12 deletions(-) diff --git a/Lombiq.Tests.UI/Extensions/VisualVerificationUITestContextExtensions.cs b/Lombiq.Tests.UI/Extensions/VisualVerificationUITestContextExtensions.cs index d1fffe698..08bf6b1d2 100644 --- a/Lombiq.Tests.UI/Extensions/VisualVerificationUITestContextExtensions.cs +++ b/Lombiq.Tests.UI/Extensions/VisualVerificationUITestContextExtensions.cs @@ -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; @@ -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."; @@ -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("-") ); }); @@ -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("-") ); }); @@ -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) {