Skip to content

Commit c86e046

Browse files
- #111 Use Atata package v3.0.0
- #112 Remove screenshot consumers configuration - #113 Replace `"artifactsPath"` configuration property with `"artifactsPathTemplate"` - #114 Remove `"timeZone"` configuration property - #115 Replace file path configuration of `"nlog-file"` log consumer with single `"fileNameTemplate"` configuration property
1 parent ed333b8 commit c86e046

File tree

14 files changed

+28
-144
lines changed

14 files changed

+28
-144
lines changed

src/Atata.Configuration.Json/Atata.Configuration.Json.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ Features:
2626
</PropertyGroup>
2727

2828
<ItemGroup>
29-
<PackageReference Include="Atata" Version="2.14.0" />
29+
<PackageReference Include="Atata" Version="3.0.0-beta.1" />
3030
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
3131
</ItemGroup>
3232

src/Atata.Configuration.Json/GlobalSuppressions.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,6 @@
3434
[assembly: SuppressMessage("Performance", "CA1819:Properties should not return arrays", Justification = "<Pending>", Scope = "member", Target = "~P:Atata.Configuration.Json.ComponentAttributesJsonSection.Properties")]
3535
[assembly: SuppressMessage("Usage", "CA2227:Collection properties should be read only", Justification = "<Pending>", Scope = "member", Target = "~P:Atata.Configuration.Json.JsonConfig`1.LogConsumers")]
3636
[assembly: SuppressMessage("Major Code Smell", "S4004:Collection properties should be readonly", Justification = "<Pending>", Scope = "member", Target = "~P:Atata.Configuration.Json.JsonConfig`1.LogConsumers")]
37-
[assembly: SuppressMessage("Usage", "CA2227:Collection properties should be read only", Justification = "<Pending>", Scope = "member", Target = "~P:Atata.Configuration.Json.JsonConfig`1.ScreenshotConsumers")]
38-
[assembly: SuppressMessage("Major Code Smell", "S4004:Collection properties should be readonly", Justification = "<Pending>", Scope = "member", Target = "~P:Atata.Configuration.Json.JsonConfig`1.ScreenshotConsumers")]
3937
[assembly: SuppressMessage("Critical Code Smell", "S1541:Methods and properties should not be too complex", Justification = "<Pending>", Scope = "member", Target = "~M:Atata.Configuration.Json.DriverJsonMapper`3.Map(Atata.Configuration.Json.DriverJsonSection,`0)")]
4038
[assembly: SuppressMessage("Critical Code Smell", "S1541:Methods and properties should not be too complex", Justification = "<Pending>", Scope = "member", Target = "~M:Atata.Configuration.Json.FirefoxDriverJsonMapper.MapOptions(Atata.Configuration.Json.DriverOptionsJsonSection,OpenQA.Selenium.Firefox.FirefoxOptions)")]
4139
[assembly: SuppressMessage("Performance", "CA1819:Properties should not return arrays", Justification = "<Pending>", Scope = "member", Target = "~P:Atata.Configuration.Json.AssemblyAttributesJsonSection.Attributes")]

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

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,21 +21,21 @@ public abstract class JsonConfig<TConfig> : JsonSection
2121

2222
/// <summary>
2323
/// Gets or sets the current <see cref="JsonConfig{TConfig}"/> instance.
24-
/// Keeps in sync with <see cref="AtataContext.Current"/> relying on its <see cref="AtataContext.ModeOfCurrent"/> value.
24+
/// Relies on <see cref="AtataContextGlobalProperties.ModeOfCurrent"/> value of <see cref="AtataContext.GlobalProperties"/>.
2525
/// </summary>
2626
public static TConfig Current
2727
{
28-
get => AtataContext.ModeOfCurrent == AtataContextModeOfCurrent.ThreadStatic
29-
? s_currentThreadStaticConfig
30-
: AtataContext.ModeOfCurrent == AtataContextModeOfCurrent.AsyncLocal
31-
? s_currentAsyncLocalConfig.Value
28+
get => AtataContext.GlobalProperties.ModeOfCurrent == AtataContextModeOfCurrent.AsyncLocal
29+
? s_currentAsyncLocalConfig.Value
30+
: AtataContext.GlobalProperties.ModeOfCurrent == AtataContextModeOfCurrent.ThreadStatic
31+
? s_currentThreadStaticConfig
3232
: s_currentStaticConfig;
3333
set
3434
{
35-
if (AtataContext.ModeOfCurrent == AtataContextModeOfCurrent.ThreadStatic)
36-
s_currentThreadStaticConfig = value;
37-
else if (AtataContext.ModeOfCurrent == AtataContextModeOfCurrent.AsyncLocal)
35+
if (AtataContext.GlobalProperties.ModeOfCurrent == AtataContextModeOfCurrent.AsyncLocal)
3836
s_currentAsyncLocalConfig.Value = value;
37+
else if (AtataContext.GlobalProperties.ModeOfCurrent == AtataContextModeOfCurrent.ThreadStatic)
38+
s_currentThreadStaticConfig = value;
3939
else
4040
s_currentStaticConfig = value;
4141
}
@@ -64,23 +64,16 @@ public DriverJsonSection Driver
6464

6565
public List<LogConsumerJsonSection> LogConsumers { get; set; }
6666

67-
public List<ScreenshotConsumerJsonSection> ScreenshotConsumers { get; set; }
68-
6967
public string BaseUrl { get; set; }
7068

7169
public Visibility? DefaultControlVisibility { get; set; }
7270

7371
public string Culture { get; set; }
7472

7573
/// <summary>
76-
/// Gets or sets the time zone identifier.
77-
/// </summary>
78-
public string TimeZone { get; set; }
79-
80-
/// <summary>
81-
/// Gets or sets the Artifacts directory path.
74+
/// Gets or sets the Artifacts directory path template.
8275
/// </summary>
83-
public string ArtifactsPath { get; set; }
76+
public string ArtifactsPathTemplate { get; set; }
8477

8578
/// <summary>
8679
/// Gets or sets the variables.

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

Lines changed: 7 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,8 @@ public static AtataContextBuilder Map<TConfig>(TConfig config, AtataContextBuild
1717
if (config.Culture is not null)
1818
builder.UseCulture(config.Culture);
1919

20-
if (config.TimeZone is not null)
21-
builder.UseTimeZone(config.TimeZone);
22-
23-
if (config.ArtifactsPath is not null)
24-
builder.UseArtifactsPath(config.ArtifactsPath);
20+
if (config.ArtifactsPathTemplate is not null)
21+
builder.UseArtifactsPathTemplate(config.ArtifactsPathTemplate);
2522

2623
if (config.Variables is not null)
2724
builder.AddVariables(config.Variables);
@@ -210,13 +207,7 @@ public static AtataContextBuilder Map<TConfig>(TConfig config, AtataContextBuild
210207
if (config.LogConsumers is not null)
211208
{
212209
foreach (var item in config.LogConsumers)
213-
MapLogConsumer(item, builder, warnings);
214-
}
215-
216-
if (config.ScreenshotConsumers is not null)
217-
{
218-
foreach (var item in config.ScreenshotConsumers)
219-
MapScreenshotConsumer(item, builder);
210+
MapLogConsumer(item, builder);
220211
}
221212

222213
if (config.Drivers is not null)
@@ -246,27 +237,15 @@ public static AtataContextBuilder Map<TConfig>(TConfig config, AtataContextBuild
246237
return builder;
247238
}
248239

249-
private static void MapLogConsumer(LogConsumerJsonSection section, AtataContextBuilder builder, ICollection<string> warnings)
240+
private static void MapLogConsumer(LogConsumerJsonSection section, AtataContextBuilder builder)
250241
{
251242
var consumerBuilder = builder.LogConsumers.Add(section.Type);
252243

253244
if (section.MinLevel != null)
254245
consumerBuilder.WithMinLevel(section.MinLevel.Value);
255246

256247
if (section.SectionEnd != null)
257-
{
258248
consumerBuilder.WithSectionEnd(section.SectionEnd.Value);
259-
}
260-
#pragma warning disable CS0618 // Type or member is obsolete
261-
else if (section.SectionFinish == false)
262-
{
263-
consumerBuilder.WithoutSectionFinish();
264-
265-
warnings.Add("""
266-
"sectionFinish" log consumer configuration property is deprecated. Instead use "sectionEnd" with one of the values: "include", "includeForBlocks", "exclude".
267-
""");
268-
}
269-
#pragma warning restore CS0618 // Type or member is obsolete
270249

271250
if (section.MessageNestingLevelIndent != null)
272251
consumerBuilder.WithMessageNestingLevelIndent(section.MessageNestingLevelIndent);
@@ -277,33 +256,6 @@ private static void MapLogConsumer(LogConsumerJsonSection section, AtataContextB
277256
if (section.MessageEndSectionPrefix != null)
278257
consumerBuilder.WithMessageEndSectionPrefix(section.MessageEndSectionPrefix);
279258

280-
if (consumerBuilder.Context is NLogFileConsumer nLogFileConsumer)
281-
ConfigureNLogFileConsumer(nLogFileConsumer, section.ExtraPropertiesMap);
282-
else
283-
consumerBuilder.WithProperties(section.ExtraPropertiesMap);
284-
}
285-
286-
// TODO: Remove this method when NLogFileConsumer will get string path/name properties.
287-
private static void ConfigureNLogFileConsumer(NLogFileConsumer consumer, Dictionary<string, object> propertiesMap)
288-
{
289-
foreach (var item in propertiesMap)
290-
{
291-
// TODO: v3. Remove first if block.
292-
if (item.Key.Equals("FolderPath", StringComparison.OrdinalIgnoreCase))
293-
consumer.DirectoryPathBuilder = _ => item.Value.ToString();
294-
else if (item.Key.Equals("DirectoryPath", StringComparison.OrdinalIgnoreCase))
295-
consumer.DirectoryPathBuilder = _ => item.Value.ToString();
296-
else if (item.Key.Equals("FileName", StringComparison.OrdinalIgnoreCase))
297-
consumer.FileNameBuilder = _ => item.Value.ToString();
298-
else if (item.Key.Equals("FilePath", StringComparison.OrdinalIgnoreCase))
299-
consumer.FilePathBuilder = _ => item.Value.ToString();
300-
}
301-
}
302-
303-
private static void MapScreenshotConsumer(ScreenshotConsumerJsonSection section, AtataContextBuilder builder)
304-
{
305-
var consumerBuilder = builder.ScreenshotConsumers.Add(section.Type);
306-
307259
consumerBuilder.WithProperties(section.ExtraPropertiesMap);
308260
}
309261

@@ -382,6 +334,9 @@ private static void MapEventSubscriptions(List<EventSubscriptionJsonSection> sec
382334

383335
private static void MapScreenshots(ScreenshotsJsonSection section, AtataContextBuilder builder)
384336
{
337+
if (!string.IsNullOrEmpty(section.FileNameTemplate))
338+
builder.Screenshots.UseFileNameTemplate(section.FileNameTemplate);
339+
385340
if (section.Strategy?.Type != null)
386341
{
387342
if (!ScreenshotStrategyAliases.TryResolve(section.Strategy.Type, out IScreenshotStrategy strategy))

src/Atata.Configuration.Json/Models/Screenshots/ScreenshotsJsonSection.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,7 @@
22

33
public sealed class ScreenshotsJsonSection
44
{
5+
public string FileNameTemplate { get; set; }
6+
57
public ScreenshotStrategyJsonSection Strategy { get; set; }
68
}

src/Atata.Configuration.Json/ScreenshotConsumerJsonSection.cs

Lines changed: 0 additions & 6 deletions
This file was deleted.

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,6 @@
118118
<None Update="Configs\LogConsumers.json">
119119
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
120120
</None>
121-
<None Update="ScreenshotConsumers.json">
122-
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
123-
</None>
124121
<None Update="Simple.json">
125122
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
126123
</None>

test/Atata.Configuration.Json.Tests/Configs/Chrome.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
"service": {
5959
"port": 555,
6060
"hostName": "127.0.0.1",
61-
"whitelistedIPAddresses": "5.5.5.5,7.7.7.7"
61+
"allowedIPAddresses": "5.5.5.5,7.7.7.7"
6262
}
6363
}
6464
}

test/Atata.Configuration.Json.Tests/Configs/Edge.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"service": {
1313
"driverPath": "{env:EdgeDriver}",
1414
"driverExecutableFileName": "msedgedriver.exe",
15-
"whitelistedIPAddresses": "ips"
15+
"allowedIPAddresses": "ips"
1616
}
1717
}
1818
}

test/Atata.Configuration.Json.Tests/Configs/StandardSettings.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@
77
},
88
"driverInitializationStage": "OnDemand",
99
"baseUrl": "https://demo.atata.io/",
10-
"artifactsPath": "{basedir}/artifacts/{build-start:yyyy}{test-suite-name-sanitized:/*}{test-name-sanitized:/*}",
11-
"timeZone": "UTC",
10+
"artifactsPathTemplate": "{test-suite-name-sanitized:/*}{test-name-sanitized:/prefix_*_postfix}",
1211

1312
"variables": {
1413
"customIntVar": 7,

0 commit comments

Comments
 (0)