Skip to content

Commit

Permalink
- #111 Use Atata package v3.0.0
Browse files Browse the repository at this point in the history
- #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
  • Loading branch information
YevgeniyShunevych committed Apr 8, 2024
1 parent ed333b8 commit c86e046
Show file tree
Hide file tree
Showing 14 changed files with 28 additions and 144 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Features:
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Atata" Version="2.14.0" />
<PackageReference Include="Atata" Version="3.0.0-beta.1" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
</ItemGroup>

Expand Down
2 changes: 0 additions & 2 deletions src/Atata.Configuration.Json/GlobalSuppressions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@
[assembly: SuppressMessage("Performance", "CA1819:Properties should not return arrays", Justification = "<Pending>", Scope = "member", Target = "~P:Atata.Configuration.Json.ComponentAttributesJsonSection.Properties")]
[assembly: SuppressMessage("Usage", "CA2227:Collection properties should be read only", Justification = "<Pending>", Scope = "member", Target = "~P:Atata.Configuration.Json.JsonConfig`1.LogConsumers")]
[assembly: SuppressMessage("Major Code Smell", "S4004:Collection properties should be readonly", Justification = "<Pending>", Scope = "member", Target = "~P:Atata.Configuration.Json.JsonConfig`1.LogConsumers")]
[assembly: SuppressMessage("Usage", "CA2227:Collection properties should be read only", Justification = "<Pending>", Scope = "member", Target = "~P:Atata.Configuration.Json.JsonConfig`1.ScreenshotConsumers")]
[assembly: SuppressMessage("Major Code Smell", "S4004:Collection properties should be readonly", Justification = "<Pending>", Scope = "member", Target = "~P:Atata.Configuration.Json.JsonConfig`1.ScreenshotConsumers")]
[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)")]
[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)")]
[assembly: SuppressMessage("Performance", "CA1819:Properties should not return arrays", Justification = "<Pending>", Scope = "member", Target = "~P:Atata.Configuration.Json.AssemblyAttributesJsonSection.Attributes")]
Expand Down
27 changes: 10 additions & 17 deletions src/Atata.Configuration.Json/JsonConfig`1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,21 @@ public abstract class JsonConfig<TConfig> : JsonSection

/// <summary>
/// Gets or sets the current <see cref="JsonConfig{TConfig}"/> instance.
/// Keeps in sync with <see cref="AtataContext.Current"/> relying on its <see cref="AtataContext.ModeOfCurrent"/> value.
/// Relies on <see cref="AtataContextGlobalProperties.ModeOfCurrent"/> value of <see cref="AtataContext.GlobalProperties"/>.
/// </summary>
public static TConfig Current
{
get => AtataContext.ModeOfCurrent == AtataContextModeOfCurrent.ThreadStatic
? s_currentThreadStaticConfig
: AtataContext.ModeOfCurrent == AtataContextModeOfCurrent.AsyncLocal
? s_currentAsyncLocalConfig.Value
get => AtataContext.GlobalProperties.ModeOfCurrent == AtataContextModeOfCurrent.AsyncLocal
? s_currentAsyncLocalConfig.Value
: AtataContext.GlobalProperties.ModeOfCurrent == AtataContextModeOfCurrent.ThreadStatic
? s_currentThreadStaticConfig
: s_currentStaticConfig;
set
{
if (AtataContext.ModeOfCurrent == AtataContextModeOfCurrent.ThreadStatic)
s_currentThreadStaticConfig = value;
else if (AtataContext.ModeOfCurrent == AtataContextModeOfCurrent.AsyncLocal)
if (AtataContext.GlobalProperties.ModeOfCurrent == AtataContextModeOfCurrent.AsyncLocal)
s_currentAsyncLocalConfig.Value = value;
else if (AtataContext.GlobalProperties.ModeOfCurrent == AtataContextModeOfCurrent.ThreadStatic)
s_currentThreadStaticConfig = value;
else
s_currentStaticConfig = value;
}
Expand Down Expand Up @@ -64,23 +64,16 @@ public DriverJsonSection Driver

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

public List<ScreenshotConsumerJsonSection> ScreenshotConsumers { get; set; }

public string BaseUrl { get; set; }

public Visibility? DefaultControlVisibility { get; set; }

public string Culture { get; set; }

/// <summary>
/// Gets or sets the time zone identifier.
/// </summary>
public string TimeZone { get; set; }

/// <summary>
/// Gets or sets the Artifacts directory path.
/// Gets or sets the Artifacts directory path template.
/// </summary>
public string ArtifactsPath { get; set; }
public string ArtifactsPathTemplate { get; set; }

/// <summary>
/// Gets or sets the variables.
Expand Down
59 changes: 7 additions & 52 deletions src/Atata.Configuration.Json/Mapping/JsonConfigMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,8 @@ public static AtataContextBuilder Map<TConfig>(TConfig config, AtataContextBuild
if (config.Culture is not null)
builder.UseCulture(config.Culture);

if (config.TimeZone is not null)
builder.UseTimeZone(config.TimeZone);

if (config.ArtifactsPath is not null)
builder.UseArtifactsPath(config.ArtifactsPath);
if (config.ArtifactsPathTemplate is not null)
builder.UseArtifactsPathTemplate(config.ArtifactsPathTemplate);

if (config.Variables is not null)
builder.AddVariables(config.Variables);
Expand Down Expand Up @@ -210,13 +207,7 @@ public static AtataContextBuilder Map<TConfig>(TConfig config, AtataContextBuild
if (config.LogConsumers is not null)
{
foreach (var item in config.LogConsumers)
MapLogConsumer(item, builder, warnings);
}

if (config.ScreenshotConsumers is not null)
{
foreach (var item in config.ScreenshotConsumers)
MapScreenshotConsumer(item, builder);
MapLogConsumer(item, builder);
}

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

private static void MapLogConsumer(LogConsumerJsonSection section, AtataContextBuilder builder, ICollection<string> warnings)
private static void MapLogConsumer(LogConsumerJsonSection section, AtataContextBuilder builder)
{
var consumerBuilder = builder.LogConsumers.Add(section.Type);

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

if (section.SectionEnd != null)
{
consumerBuilder.WithSectionEnd(section.SectionEnd.Value);
}
#pragma warning disable CS0618 // Type or member is obsolete
else if (section.SectionFinish == false)
{
consumerBuilder.WithoutSectionFinish();

warnings.Add("""
"sectionFinish" log consumer configuration property is deprecated. Instead use "sectionEnd" with one of the values: "include", "includeForBlocks", "exclude".
""");
}
#pragma warning restore CS0618 // Type or member is obsolete

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

if (consumerBuilder.Context is NLogFileConsumer nLogFileConsumer)
ConfigureNLogFileConsumer(nLogFileConsumer, section.ExtraPropertiesMap);
else
consumerBuilder.WithProperties(section.ExtraPropertiesMap);
}

// TODO: Remove this method when NLogFileConsumer will get string path/name properties.
private static void ConfigureNLogFileConsumer(NLogFileConsumer consumer, Dictionary<string, object> propertiesMap)
{
foreach (var item in propertiesMap)
{
// TODO: v3. Remove first if block.
if (item.Key.Equals("FolderPath", StringComparison.OrdinalIgnoreCase))
consumer.DirectoryPathBuilder = _ => item.Value.ToString();
else if (item.Key.Equals("DirectoryPath", StringComparison.OrdinalIgnoreCase))
consumer.DirectoryPathBuilder = _ => item.Value.ToString();
else if (item.Key.Equals("FileName", StringComparison.OrdinalIgnoreCase))
consumer.FileNameBuilder = _ => item.Value.ToString();
else if (item.Key.Equals("FilePath", StringComparison.OrdinalIgnoreCase))
consumer.FilePathBuilder = _ => item.Value.ToString();
}
}

private static void MapScreenshotConsumer(ScreenshotConsumerJsonSection section, AtataContextBuilder builder)
{
var consumerBuilder = builder.ScreenshotConsumers.Add(section.Type);

consumerBuilder.WithProperties(section.ExtraPropertiesMap);
}

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

private static void MapScreenshots(ScreenshotsJsonSection section, AtataContextBuilder builder)
{
if (!string.IsNullOrEmpty(section.FileNameTemplate))
builder.Screenshots.UseFileNameTemplate(section.FileNameTemplate);

if (section.Strategy?.Type != null)
{
if (!ScreenshotStrategyAliases.TryResolve(section.Strategy.Type, out IScreenshotStrategy strategy))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,7 @@

public sealed class ScreenshotsJsonSection
{
public string FileNameTemplate { get; set; }

public ScreenshotStrategyJsonSection Strategy { get; set; }
}
6 changes: 0 additions & 6 deletions src/Atata.Configuration.Json/ScreenshotConsumerJsonSection.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,6 @@
<None Update="Configs\LogConsumers.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="ScreenshotConsumers.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Simple.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
Expand Down
2 changes: 1 addition & 1 deletion test/Atata.Configuration.Json.Tests/Configs/Chrome.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
"service": {
"port": 555,
"hostName": "127.0.0.1",
"whitelistedIPAddresses": "5.5.5.5,7.7.7.7"
"allowedIPAddresses": "5.5.5.5,7.7.7.7"
}
}
}
2 changes: 1 addition & 1 deletion test/Atata.Configuration.Json.Tests/Configs/Edge.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"service": {
"driverPath": "{env:EdgeDriver}",
"driverExecutableFileName": "msedgedriver.exe",
"whitelistedIPAddresses": "ips"
"allowedIPAddresses": "ips"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
},
"driverInitializationStage": "OnDemand",
"baseUrl": "https://demo.atata.io/",
"artifactsPath": "{basedir}/artifacts/{build-start:yyyy}{test-suite-name-sanitized:/*}{test-name-sanitized:/*}",
"timeZone": "UTC",
"artifactsPathTemplate": "{test-suite-name-sanitized:/*}{test-name-sanitized:/prefix_*_postfix}",

"variables": {
"customIntVar": 7,
Expand Down
6 changes: 3 additions & 3 deletions test/Atata.Configuration.Json.Tests/DriverTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ private static void VerifyChromeService(ChromeDriverService service)
{
service.Port.Should().Be(555);
service.HostName.Should().Be("127.0.0.1");
service.WhitelistedIPAddresses.Should().Be("5.5.5.5,7.7.7.7");
service.AllowedIPAddresses.Should().Be("5.5.5.5,7.7.7.7");
}

[Test]
Expand Down Expand Up @@ -256,7 +256,7 @@ private static void VerifyChromeJsonConfig(JsonConfig config)
{
["port"] = 555,
["hostName"] = "127.0.0.1",
["whitelistedIPAddresses"] = "5.5.5.5,7.7.7.7"
["allowedIPAddresses"] = "5.5.5.5,7.7.7.7"
});
}
}
Expand Down Expand Up @@ -374,7 +374,7 @@ public void Edge()

context.Options.PageLoadStrategy.Should().Be(PageLoadStrategy.Eager);

context.Service.WhitelistedIPAddresses.Should().Be("ips");
context.Service.AllowedIPAddresses.Should().Be("ips");
}

[Test]
Expand Down
33 changes: 0 additions & 33 deletions test/Atata.Configuration.Json.Tests/ScreenshotConsumerTests.cs

This file was deleted.

17 changes: 0 additions & 17 deletions test/Atata.Configuration.Json.Tests/ScreenshotConsumers.json

This file was deleted.

8 changes: 2 additions & 6 deletions test/Atata.Configuration.Json.Tests/StandardSettingsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,9 @@ public void Regular()

result.ValueOf(x => x.Artifacts.FullName.Value).Should.Be(
Path.Combine(
AppDomain.CurrentDomain.BaseDirectory,
"artifacts",
DateTime.Now.Year.ToString(),
AtataContext.GlobalProperties.ArtifactsRootPath,
nameof(StandardSettingsTests),
TestContext.CurrentContext.Test.Name));

result.ValueOf(x => x.TimeZone.Id).Should.Be("UTC");
$"prefix_{TestContext.CurrentContext.Test.Name}_postfix"));

result.ValueOf(x => x.Variables["customIntVar"]).Should.Be(7L);
result.ValueOf(x => x.Variables["customStringVar"]).Should.Be("strvar");
Expand Down

0 comments on commit c86e046

Please sign in to comment.