From 452ce5e79d6e3c79e047f3732b152ee7e0b4a937 Mon Sep 17 00:00:00 2001 From: Nick Chursin Date: Mon, 17 Jan 2022 00:57:10 +0200 Subject: [PATCH] #46 feature --- src/allure-nunit-tests/AllureDiffTest.cs | 35 +++++++++++++++++++ .../allure-nunit-tests.csproj | 2 +- src/allure-nunit/Core/AllureExtensions.cs | 14 ++++++++ src/allure-nunit/allure-nunit.csproj | 8 +++-- 4 files changed, 55 insertions(+), 4 deletions(-) create mode 100644 src/allure-nunit-tests/AllureDiffTest.cs diff --git a/src/allure-nunit-tests/AllureDiffTest.cs b/src/allure-nunit-tests/AllureDiffTest.cs new file mode 100644 index 0000000..8d39714 --- /dev/null +++ b/src/allure-nunit-tests/AllureDiffTest.cs @@ -0,0 +1,35 @@ +using Allure.Commons; +using NUnit.Allure.Attributes; +using NUnit.Framework; +using NUnit.Allure.Core; + +namespace allure_nunit_tests +{ + [AllureSuite("Tests - ScreenDiff")] + public class AllureDiffTest : BaseTest + { + [Test] + [AllureName("Simple test with diff")] + public void DiffTest() + { + AddDiffs(); + } + + [Test] + [AllureName("Diff test with step")] + public void DiffStepsTest() + { + AddDiffs(); + AllureLifecycle.Instance.WrapInStep(() => + { + AllureLifecycle.Instance.WrapInStep(() => { AddDiffs(); }, "Step Inside"); + AddDiffs(); + }, "StepOutSide"); + } + + public static void AddDiffs() + { + AllureLifecycle.Instance.AddScreenDiff("logo.png", "logo.png", "logo.png"); + } + } +} \ No newline at end of file diff --git a/src/allure-nunit-tests/allure-nunit-tests.csproj b/src/allure-nunit-tests/allure-nunit-tests.csproj index 6c00489..4044323 100644 --- a/src/allure-nunit-tests/allure-nunit-tests.csproj +++ b/src/allure-nunit-tests/allure-nunit-tests.csproj @@ -1,7 +1,7 @@  - netcoreapp3.1 + net5.0 allure_nunit_tests false Library diff --git a/src/allure-nunit/Core/AllureExtensions.cs b/src/allure-nunit/Core/AllureExtensions.cs index 5e72221..3103a69 100644 --- a/src/allure-nunit/Core/AllureExtensions.cs +++ b/src/allure-nunit/Core/AllureExtensions.cs @@ -1,7 +1,9 @@ using System; +using System.Reflection; using System.Runtime.CompilerServices; using Allure.Commons; using NUnit.Framework.Internal; +using System.Linq; namespace NUnit.Allure.Core { @@ -110,5 +112,17 @@ public static T WrapInStep(this AllureLifecycle lifecycle, Func func, stri throw; } } + + + /// + /// AllureNUnit AddScreenDiff wrapper method. + /// + public static void AddScreenDiff(this AllureLifecycle lifecycle, string expected, string actual, string diff) + { + var storageMain = lifecycle.GetType().GetField("storage", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(lifecycle); + var storageInternal = storageMain.GetType().GetField("storage", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(storageMain); + var keys = (storageInternal as System.Collections.Concurrent.ConcurrentDictionary).Keys.ToList(); + AllureLifecycle.Instance.AddScreenDiff(keys.Find(key => key.Contains("-tr-")), expected, actual, diff); + } } } \ No newline at end of file diff --git a/src/allure-nunit/allure-nunit.csproj b/src/allure-nunit/allure-nunit.csproj index cc27cdf..3fd0647 100644 --- a/src/allure-nunit/allure-nunit.csproj +++ b/src/allure-nunit/allure-nunit.csproj @@ -31,9 +31,11 @@ Always - - - + + Always + + +