Skip to content

Commit

Permalink
Merge pull request #258 from Lombiq/task/nodejs-extensions
Browse files Browse the repository at this point in the history
OSOE-84: Merge task/nodejs-extensions to dev
  • Loading branch information
0liver authored Jan 25, 2023
2 parents d8761f7 + 161ea5e commit b2a95a9
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 78 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public static class FailureDumpUITestContextExtensions
/// <param name="context"><see cref="UITestContext"/> instance.</param>
/// <param name="fileName">The name of the file.</param>
/// <param name="action">Gets called in failure dump collection.</param>
/// <param name="messageIfExists">A message to display in case the desired file already exists in the dump.</param>
public static void AppendFailureDump(
this UITestContext context,
string fileName,
Expand All @@ -33,6 +34,7 @@ public static void AppendFailureDump(
/// <param name="context"><see cref="UITestContext"/> instance.</param>
/// <param name="fileName">The name of the file.</param>
/// <param name="content">File content.</param>
/// <param name="messageIfExists">A message to display in case the desired file already exists in the dump.</param>
public static void AppendFailureDump(
this UITestContext context,
string fileName,
Expand All @@ -54,6 +56,7 @@ public static void AppendFailureDump(
/// <param name="content">File content.</param>
/// <param name="getStream">Function to get a new <see cref="Stream"/> from content.</param>
/// <param name="dispose">Action to dispose the content, if required. Can be null.</param>
/// <param name="messageIfExists">A message to display in case the desired file already exists in the dump.</param>
public static void AppendFailureDump<TContent>(
this UITestContext context,
string fileName,
Expand All @@ -71,9 +74,8 @@ public static void AppendFailureDump<TContent>(
/// </summary>
/// <param name="context"><see cref="UITestContext"/> instance.</param>
/// <param name="fileName">The name of the file.</param>
/// <param name="image">
/// File content. The <see cref="Image"/> will be disposed at the end.
/// </param>
/// <param name="image">File content. The <see cref="Image"/> will be disposed at the end.</param>
/// <param name="messageIfExists">A message to display in case the desired file already exists in the dump.</param>
public static void AppendFailureDump(
this UITestContext context,
string fileName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -400,13 +400,7 @@ private static void AssertVisualVerification(
using var elementImageOriginal = context.TakeElementScreenshot(element).ShouldNotBeNull();

var originalElementScreenshotFileName =
new[]
{
configuration.FileNamePrefix,
VisualVerificationMatchNames.ElementImageFileName,
configuration.FileNameSuffix,
}
.JoinNotNullOrEmpty("-");
configuration.WrapFileName(VisualVerificationMatchNames.ElementImageFileName);

// Checking the dimensions of captured image. This needs to happen before any other comparisons, because that
// can only be done on images with the same dimensions.
Expand Down Expand Up @@ -446,7 +440,7 @@ private static void AssertVisualVerification(
.ShouldNotBeNull();

// Now we are one step away from the end. Here we create a statistical summary of the differences between the
// captured and the baseline image. In the end, the lower values are better. You can read more about how these
// captured and the baseline image. In the end, lower values are better. You can read more about how these
// statistical calculations are created here:
// https://github.com/Codeuctivity/ImageSharp.Compare/blob/2.0.46/ImageSharpCompare/ImageSharpCompare.cs#L218.
var diff = baselineImageCropped.CompareTo(elementImageCropped);
Expand All @@ -458,75 +452,21 @@ private static void AssertVisualVerification(
catch
{
// Here we append all the relevant items to the failure dump to help the investigation.
// The full-page screenshot
context.AddImageToFailureDump(
new[]
{
configuration.FileNamePrefix,
VisualVerificationMatchNames.FullScreenImageFileName,
configuration.FileNameSuffix,
}
.JoinNotNullOrEmpty("-"),
fullScreenImage);

// The original element screenshot
context.AddImageToFailureDump(originalElementScreenshotFileName, elementImageOriginal);
void AddImageToFailureDumpLocal(string fileName, Image image, bool dontWrap = false) =>
context.AddImageToFailureDump(dontWrap ? fileName : configuration.WrapFileName(fileName), image);

AddImageToFailureDumpLocal(VisualVerificationMatchNames.FullScreenImageFileName, fullScreenImage);
AddImageToFailureDumpLocal(originalElementScreenshotFileName, elementImageOriginal, dontWrap: true);
AddImageToFailureDumpLocal(VisualVerificationMatchNames.BaselineImageFileName, baselineImageOriginal);
AddImageToFailureDumpLocal(VisualVerificationMatchNames.CroppedBaselineImageFileName, baselineImageCropped);
AddImageToFailureDumpLocal(VisualVerificationMatchNames.CroppedElementImageFileName, elementImageCropped);
AddImageToFailureDumpLocal(VisualVerificationMatchNames.DiffImageFileName, diffImage);

// The original baseline image
context.AddImageToFailureDump(
new[]
{
configuration.FileNamePrefix,
VisualVerificationMatchNames.BaselineImageFileName,
configuration.FileNameSuffix,
}
.JoinNotNullOrEmpty("-"),
baselineImageOriginal);

// The cropped baseline image
context.AddImageToFailureDump(
new[]
{
configuration.FileNamePrefix,
VisualVerificationMatchNames.CroppedBaselineImageFileName,
configuration.FileNameSuffix,
}
.JoinNotNullOrEmpty("-"),
baselineImageCropped);

// The cropped element image
context.AddImageToFailureDump(
new[]
{
configuration.FileNamePrefix,
VisualVerificationMatchNames.CroppedElementImageFileName,
configuration.FileNameSuffix,
}
.JoinNotNullOrEmpty("-"),
elementImageCropped);

// The diff image
context.AddImageToFailureDump(
new[]
{
configuration.FileNamePrefix,
VisualVerificationMatchNames.DiffImageFileName,
configuration.FileNameSuffix,
}
.JoinNotNullOrEmpty("-"),
diffImage);

// The diff stats
// The diff stats.
context.AppendFailureDump(
Path.Combine(
VisualVerificationMatchNames.DumpFolderName,
new[]
{
configuration.FileNamePrefix,
VisualVerificationMatchNames.DiffLogFileName,
configuration.FileNameSuffix,
}
.JoinNotNullOrEmpty("-")),
configuration.WrapFileName(VisualVerificationMatchNames.DiffLogFileName)),
content: string.Format(
CultureInfo.InvariantCulture,
@"
Expand Down
2 changes: 1 addition & 1 deletion Lombiq.Tests.UI/Lombiq.Tests.UI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@
<PackageReference Include="Lombiq.HelpfulLibraries.Cli" Version="5.1.0" />
<PackageReference Include="Lombiq.HelpfulLibraries.OrchardCore" Version="5.1.0" />
<PackageReference Include="Lombiq.HelpfulLibraries.RestEase" Version="5.1.0" />
<PackageReference Include="Lombiq.Npm.Targets" Version="1.2.1" />
<PackageReference Include="Lombiq.Npm.Targets" Version="1.2.1-alpha.3.osoe-84" />
</ItemGroup>

<!-- These are necessary for symbols NuGet packaging, otherwise Shouldly would prevent PDBs to be packaged, see:
Expand Down
10 changes: 10 additions & 0 deletions Lombiq.Tests.UI/Models/VisualVerificationMatchConfiguration.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using System;

namespace Lombiq.Tests.UI.Models;

public class VisualVerificationMatchConfiguration<TSelf>
Expand Down Expand Up @@ -34,6 +36,14 @@ public TSelf WithFileNameSuffix(string value)

return (TSelf)this;
}

public string WrapFileName(string fileName) =>
new[]
{
FileNamePrefix,
fileName,
FileNameSuffix,
}.JoinNotNullOrEmpty("-");
}

public class VisualMatchConfiguration : VisualVerificationMatchConfiguration<VisualMatchConfiguration> { }
2 changes: 1 addition & 1 deletion Lombiq.Tests.UI/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit b2a95a9

Please sign in to comment.