From 366253f3817e2d89a169244ce607d43657e5cdfd Mon Sep 17 00:00:00 2001 From: YevgeniyShunevych Date: Tue, 17 Oct 2023 13:08:47 +0200 Subject: [PATCH] #785 Add `Report.Setup(Func function)` method --- src/Atata/Logging/ReportExtensions.cs | 24 +++++++++++++++++++ .../ReportExtensionsTests.cs | 20 ++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 src/Atata/Logging/ReportExtensions.cs create mode 100644 test/Atata.IntegrationTests/ReportExtensionsTests.cs diff --git a/src/Atata/Logging/ReportExtensions.cs b/src/Atata/Logging/ReportExtensions.cs new file mode 100644 index 00000000..354c8520 --- /dev/null +++ b/src/Atata/Logging/ReportExtensions.cs @@ -0,0 +1,24 @@ +namespace Atata; + +/// +/// Provides a set of extension methods for . +/// +public static class ReportExtensions +{ + /// + /// Executes the specified function and represents it in a log as a setup section with the message like "Set up "<Some>" page". + /// The setup function time is not counted as a "Test body" execution time, but counted as "Setup" time. + /// + /// The type of the owner. + /// The type of the result page object. + /// The object. + /// The setup function. + /// The result page object of the . + public static TPageObject Setup(this Report report, Func function) + where TPageObject : PageObject + { + string componentFullName = UIComponentResolver.ResolvePageObjectFullName(); + + return report.Setup($"Set up {componentFullName}", function); + } +} diff --git a/test/Atata.IntegrationTests/ReportExtensionsTests.cs b/test/Atata.IntegrationTests/ReportExtensionsTests.cs new file mode 100644 index 00000000..713b7698 --- /dev/null +++ b/test/Atata.IntegrationTests/ReportExtensionsTests.cs @@ -0,0 +1,20 @@ +namespace Atata.IntegrationTests; + +public class ReportExtensionsTests : UITestFixture +{ + [Test] + public void Setup() + { + AtataContext.Current.Report.Setup(x => x + .Go.To()); + + VerifyLastLogMessagesMatch( + minLogLevel: LogLevel.Trace, + "^> Set up \"\" page$", + "^> Go to \"\" page", + "^> Navigate to URL", + "^< Navigate to URL", + "^< Go to \"\" page", + "^< Set up \"\" page"); + } +}