Skip to content

Commit 5f54d40

Browse files
#99 Add support of browser logs monitoring configuration
1 parent 1d43b8d commit 5f54d40

File tree

6 files changed

+51
-2
lines changed

6 files changed

+51
-2
lines changed

src/Atata.Configuration.Json/JsonConfig`1.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,4 +270,9 @@ public double? RetryInterval
270270
/// Gets or sets the page snapshots configuration.
271271
/// </summary>
272272
public PageSnapshotsJsonSection PageSnapshots { get; set; }
273+
274+
/// <summary>
275+
/// Gets or sets the browser logs configuration.
276+
/// </summary>
277+
public BrowserLogsJsonSection BrowserLogs { get; set; }
273278
}

src/Atata.Configuration.Json/Mapping/JsonConfigMapper.cs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,9 @@ public static AtataContextBuilder Map<TConfig>(TConfig config, AtataContextBuild
168168
if (config.PageSnapshots is not null)
169169
MapPageSnapshots(config.PageSnapshots, builder);
170170

171+
if (config.BrowserLogs is not null)
172+
MapBrowserLogs(config.BrowserLogs, builder);
173+
171174
return builder;
172175
}
173176

@@ -295,7 +298,7 @@ private static void MapEventSubscriptions(List<EventSubscriptionJsonSection> sec
295298

296299
private static void MapScreenshots(ScreenshotsJsonSection section, AtataContextBuilder builder)
297300
{
298-
if (section?.Strategy?.Type != null)
301+
if (section.Strategy?.Type != null)
299302
{
300303
if (!ScreenshotStrategyAliases.TryResolve(section.Strategy.Type, out IScreenshotStrategy strategy))
301304
strategy = (IScreenshotStrategy)CreateObject(
@@ -312,7 +315,7 @@ private static void MapPageSnapshots(PageSnapshotsJsonSection section, AtataCont
312315
if (!string.IsNullOrEmpty(section.FileNameTemplate))
313316
builder.PageSnapshots.UseFileNameTemplate(section.FileNameTemplate);
314317

315-
if (section?.Strategy?.Type != null)
318+
if (section.Strategy?.Type != null)
316319
{
317320
if (!PageSnapshotStrategyAliases.TryResolve(section.Strategy.Type, out IPageSnapshotStrategy strategy))
318321
strategy = (IPageSnapshotStrategy)CreateObject(
@@ -324,6 +327,15 @@ private static void MapPageSnapshots(PageSnapshotsJsonSection section, AtataCont
324327
}
325328
}
326329

330+
private static void MapBrowserLogs(BrowserLogsJsonSection section, AtataContextBuilder builder)
331+
{
332+
if (section.Log)
333+
builder.BrowserLogs.UseLog(section.Log);
334+
335+
if (section.MinLevelOfWarning is not null)
336+
builder.BrowserLogs.UseMinLevelOfWarning(section.MinLevelOfWarning);
337+
}
338+
327339
private static object CreateObject(string typeName, Dictionary<string, object> valuesMap, string assemblyNamePatternToFindType)
328340
{
329341
IObjectConverter objectConverter = new ObjectConverter
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
namespace Atata.Configuration.Json;
2+
3+
public sealed class BrowserLogsJsonSection
4+
{
5+
public bool Log { get; set; }
6+
7+
public LogLevel? MinLevelOfWarning { get; set; }
8+
}

test/Atata.Configuration.Json.Tests/Atata.Configuration.Json.Tests.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@
6666
<None Update="Configs\EventSubscriptions\HandlerType.json">
6767
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
6868
</None>
69+
<None Update="Configs\BrowserLogs.json">
70+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
71+
</None>
6972
<None Update="Configs\StandardSettings.json">
7073
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
7174
</None>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
namespace Atata.Configuration.Json.Tests;
2+
3+
public sealed class BrowserLogsTests : TestFixture
4+
{
5+
[Test]
6+
public void WithAllPropertiesSet()
7+
{
8+
var builder = AtataContext.Configure().
9+
ApplyJsonConfig($"Configs/BrowserLogs");
10+
11+
builder.BuildingContext.ToResultSubject()
12+
.ValueOf(x => x.BrowserLogs.Log).Should.BeTrue()
13+
.ValueOf(x => x.BrowserLogs.MinLevelOfWarning).Should.Be(LogLevel.Warn);
14+
}
15+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"browserLogs": {
3+
"log": true,
4+
"minLevelOfWarning": "warn"
5+
}
6+
}

0 commit comments

Comments
 (0)