Skip to content

Commit 1d0dadc

Browse files
committed
Logging attempt #1
1 parent 8b5f445 commit 1d0dadc

File tree

4 files changed

+48
-3
lines changed

4 files changed

+48
-3
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using NUnit.Framework.Interfaces;
2+
using SeleniumTests.lib.helpers;
3+
4+
namespace SeleniumTests.lib.Base;
5+
6+
public abstract class BaseTestWithLogging
7+
{
8+
[TearDown]
9+
public void TrackTestResult()
10+
{
11+
var testName = TestContext.CurrentContext.Test.Name;
12+
var passed = TestContext.CurrentContext.Result.Outcome.Status == TestStatus.Passed;
13+
TestResultLogger.Log(testName, passed);
14+
}
15+
16+
[OneTimeTearDown]
17+
public void FinalSummary()
18+
{
19+
TestResultLogger.PrintSummary();
20+
}
21+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
using System.Collections.Concurrent;
2+
3+
namespace SeleniumTests.lib.helpers;
4+
5+
public static class TestResultLogger
6+
{
7+
private static readonly ConcurrentBag<(string Name, string Status)> _results = new();
8+
9+
public static void Log(string testName, bool passed)
10+
{
11+
var status = passed ? "\x1b[32m✅ PASSED\x1b[0m" : "\x1b[31m❌ FAILED\x1b[0m";
12+
_results.Add((testName, status));
13+
}
14+
15+
public static void PrintSummary()
16+
{
17+
Console.WriteLine("\n📊 Test Summary:");
18+
Console.WriteLine(new string('-', 50));
19+
foreach (var (name, status) in _results)
20+
{
21+
Console.WriteLine($"{status,-15} | {name}");
22+
}
23+
Console.WriteLine(new string('-', 50));
24+
}
25+
}

SeleniumTests/tests/UiHomePageTests.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
using NUnit.Framework;
21
using SeleniumTests.lib.Base;
32
using SeleniumTests.lib.config;
43
using SeleniumTests.lib.pages;

SeleniumTests/tests/fixtures/BookStoreFixture.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
using NUnit.Framework;
1+
using SeleniumTests.lib.Base;
22
using SeleniumTests.lib.helpers;
33

44
namespace SeleniumTests.tests.fixtures;
55

6-
public class BookStoreFixture
6+
public class BookStoreFixture : BaseTestWithLogging
77
{
88
protected BookStoreClient Client = null!;
99

0 commit comments

Comments
 (0)