How to configure Atata reporting to Extent Reports.
In addition to Atata package, the ExtentReports package should be added to the project.
The functionality for Extent Reports is implemented in 3 class files:
ExtentHtmlReporter
).
Saves HTML report to AtataContext Artifacts root directory.
Other Extent reporters can also be attached.You can copy these files to your project and modify according to your project’s needs.
In order to connect Extent Reports functionality to Atata,
ExtentLogConsumer
and ExtentScreenshotFileEventHandler
should be added to AtataContextBuilder
.
ExtentScreenshotFileEventHandler
can be added to EventSubscriptions
in SetUpFixture
.ExtentContext.Reports.Flush()
method should be executed
as a final action of a tests run.
In NUnit a good place for it is OneTimeTearDown
method of SetUpFixture.cs
.using Atata;
using Atata.ExtentReports;
using NUnit.Framework;
namespace AtataSamples.ExtentReports;
[SetUpFixture]
public class SetUpFixture
{
[OneTimeSetUp]
public void GlobalSetUp()
{
AtataContext.GlobalConfiguration
.UseChrome()
.WithArguments("window-size=1024,768", "headless")
.UseBaseUrl("https://demo.atata.io/")
.UseCulture("en-US")
.UseAllNUnitFeatures()
.ScreenshotConsumers.AddFile()
.EventSubscriptions.Add(new ExtentScreenshotFileEventHandler());
AtataContext.GlobalConfiguration.AutoSetUpDriverToUse();
}
[OneTimeTearDown]
public void GlobalTearDown() =>
ExtentContext.Reports.Flush();
}
UITestFixture
is often used as a base UI test fixture class.
For this sample the implementation is more complicated as usual,
because additionally AtataContext
for fixture is also added.
using Atata;
using Atata.ExtentReports;
using NUnit.Framework;
using NUnit.Framework.Internal;
namespace AtataSamples.ExtentReports;
[TestFixture]
[Parallelizable(ParallelScope.Fixtures)]
public class UITestFixture
{
protected AtataContext FixtureContext { get; set; }
protected virtual bool UseFixtureDriverForTests => false;
[OneTimeSetUp]
public void InitFixtureContext() =>
FixtureContext = AtataContext.Configure()
.UseDriverInitializationStage(AtataContextDriverInitializationStage.OnDemand)
.LogConsumers.Add<ExtentLogConsumer>()
.WithMinLevel(LogLevel.Warn)
.Build();
[OneTimeTearDown]
public void DisposeFixtureContext() =>
FixtureContext?.Dispose();
[SetUp]
public void SetUp()
{
var testContextBuilder = AtataContext.Configure()
.LogConsumers.Add<ExtentLogConsumer>();
if (UseFixtureDriverForTests)
testContextBuilder.UseDriver(FixtureContext.Driver);
testContextBuilder.Build();
}
[TearDown]
public void TearDown() =>
AtataContext.Current?.CleanUp(quitDriver: !UseFixtureDriverForTests);
protected virtual TPageObject BeingOn<TPageObject>()
where TPageObject : PageObject<TPageObject> =>
Go.To<TPageObject>(navigate: false);
}
using Atata;
using NUnit.Framework;
namespace AtataSamples.ExtentReports;
public class UsingOwnDriverTests : UITestFixture
{
[Test]
public void Test1() =>
Go.To<HomePage>()
.Report.Screenshot()
.Header.Should.Contain("Atata");
[Test]
public void Test2() =>
Go.To<HomePage>()
.Report.Screenshot()
.AggregateAssert(x => x
.PageTitle.Should.Contain("Atata")
.Header.Should.Contain("Atata"));
}
For testing purposes, screenshots are captured right after a navigation to the home page. Also when the test fails at any moment, a screenshot is captured as well.
In this test fixture class we create one shared driver for all class tests,
do navigation once in SetUpFixture
method,
then every test starts with already navigated page
and does its verification.
using Atata;
using NUnit.Framework;
namespace AtataSamples.ExtentReports;
public class UsingSameDriverTests : UITestFixture
{
protected override bool UseFixtureDriverForTests => true;
[OneTimeSetUp]
public void SetUpFixture() =>
Go.To<SignInPage>();
[Test]
public void Email() =>
BeingOn<SignInPage>()
.Email.Should.BeVisible();
[Test]
public void Password() =>
BeingOn<SignInPage>()
.Password.Should.BeVisible();
}
After a tests run, the generated Extent HTML report can be found by relative path:
\AtataSamples.ExtentReports\bin\Debug\net6.0\artifacts\{DATETIME_OF_RUN}\index.html
.