Skip to content

Commit

Permalink
#698 Add page snapshot functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
YevgeniyShunevych committed Nov 16, 2022
1 parent 9215071 commit 6e1f9ec
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 17 deletions.
28 changes: 18 additions & 10 deletions src/Atata/Logging/Snapshots/PageSnapshotTaker.cs
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;

namespace Atata
{
Expand Down Expand Up @@ -29,16 +30,23 @@ public void TakeSnapshot(string title = null)

_snapshotNumber++;

_context.Log.ExecuteSection(
new TakePageSnapshotLogSection(_snapshotNumber, title),
() =>
{
FileContentWithExtension fileContent = _snapshotStrategy.TakeSnapshot(_context);
string filePath = FormatFilePath(title);
try
{
_context.Log.ExecuteSection(
new TakePageSnapshotLogSection(_snapshotNumber, title),
() =>
{
FileContentWithExtension fileContent = _snapshotStrategy.TakeSnapshot(_context);
string filePath = FormatFilePath(title);
_context.AddArtifact(filePath, fileContent, ArtifactTypes.PageSnapshot);
return filePath + fileContent.Extension;
});
_context.AddArtifact(filePath, fileContent, ArtifactTypes.PageSnapshot);
return filePath + fileContent.Extension;
});
}
catch (Exception e)
{
_context.Log.Error("Page snapshot failed", e);
}
}

private string FormatFilePath(string title)
Expand Down
48 changes: 41 additions & 7 deletions test/Atata.IntegrationTests/Context/AtataContextTests.cs
Expand Up @@ -196,15 +196,12 @@ public class FillTemplateString : UITestFixtureBase

public class TakeScreenshot : UITestFixtureBase
{
[SetUp]
public void SetUp() =>
ConfigureBaseAtataContext()
.ScreenshotConsumers.AddFile()
.Build();

[Test]
public void WhenNavigated()
{
ConfigureBaseAtataContext()
.ScreenshotConsumers.AddFile()
.Build();
Go.To<InputPage>();

AtataContext.Current.TakeScreenshot();
Expand All @@ -215,17 +212,37 @@ public void WhenNavigated()
[Test]
public void WhenNoNavigation()
{
ConfigureBaseAtataContext()
.ScreenshotConsumers.AddFile()
.Build();

AtataContext.Current.TakeScreenshot();

AtataContext.Current.Artifacts.Should.ContainFile("01.png");
}

[Test]
public void WhenThrows()
{
ConfigureBaseAtataContext()
.ScreenshotConsumers.Add(Mock.Of<IScreenshotConsumer>(MockBehavior.Strict))
.Build();
Go.To<InputPage>();

AtataContext.Current.TakeScreenshot();

VerifyLastLogMessagesContain(LogLevel.Error, "Screenshot failed");
AtataContext.Current.Artifacts.Should.Not.Exist();
}
}

public class TakePageSnapshot : UITestFixture
public class TakePageSnapshot : UITestFixtureBase
{
[Test]
public void WhenNavigated()
{
ConfigureBaseAtataContext()
.Build();
Go.To<InputPage>();

AtataContext.Current.TakePageSnapshot();
Expand All @@ -236,9 +253,26 @@ public void WhenNavigated()
[Test]
public void WhenNoNavigation()
{
ConfigureBaseAtataContext()
.Build();

AtataContext.Current.TakePageSnapshot();

AtataContext.Current.Artifacts.Should.ContainFile("01.mhtml");
}

[Test]
public void WhenThrows()
{
ConfigureBaseAtataContext()
.PageSnapshots.UseStrategy(Mock.Of<IPageSnapshotStrategy>(MockBehavior.Strict))
.Build();
Go.To<InputPage>();

AtataContext.Current.TakePageSnapshot();

VerifyLastLogMessagesContain(LogLevel.Error, "Page snapshot failed");
AtataContext.Current.Artifacts.Should.Not.Exist();
}
}
}

0 comments on commit 6e1f9ec

Please sign in to comment.