Skip to content

Commit

Permalink
#785 Add Report.Setup<TResult>(Func<TOwner, TPageObject> function)
Browse files Browse the repository at this point in the history
…method
  • Loading branch information
YevgeniyShunevych committed Oct 17, 2023
1 parent 0c93dae commit 366253f
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/Atata/Logging/ReportExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
namespace Atata;

/// <summary>
/// Provides a set of extension methods for <see cref="Report{TOwner}"/>.
/// </summary>
public static class ReportExtensions
{
/// <summary>
/// Executes the specified function and represents it in a log as a setup section with the message like <c>"Set up "&lt;Some&gt;" page"</c>.
/// The setup function time is not counted as a "Test body" execution time, but counted as "Setup" time.
/// </summary>
/// <typeparam name="TOwner">The type of the owner.</typeparam>
/// <typeparam name="TPageObject">The type of the result page object.</typeparam>
/// <param name="report">The <see cref="Report{TOwner}"/> object.</param>
/// <param name="function">The setup function.</param>
/// <returns>The result page object of the <paramref name="function"/>.</returns>
public static TPageObject Setup<TOwner, TPageObject>(this Report<TOwner> report, Func<TOwner, TPageObject> function)
where TPageObject : PageObject<TPageObject>
{
string componentFullName = UIComponentResolver.ResolvePageObjectFullName<TPageObject>();

return report.Setup($"Set up {componentFullName}", function);
}
}
20 changes: 20 additions & 0 deletions test/Atata.IntegrationTests/ReportExtensionsTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
namespace Atata.IntegrationTests;

public class ReportExtensionsTests : UITestFixture
{
[Test]
public void Setup()
{
AtataContext.Current.Report.Setup(x => x
.Go.To<OrdinaryPage>());

VerifyLastLogMessagesMatch(
minLogLevel: LogLevel.Trace,
"^> Set up \"<ordinary>\" page$",
"^> Go to \"<ordinary>\" page",
"^> Navigate to URL",
"^< Navigate to URL",
"^< Go to \"<ordinary>\" page",
"^< Set up \"<ordinary>\" page");
}
}

0 comments on commit 366253f

Please sign in to comment.