Skip to content

Commit 66b9074

Browse files
Merge pull request #225 from aquality-automation/feature/support-logging-preferences
Support logging preferences from settings.json +semver: feature
2 parents bf49950 + b2cf3c4 commit 66b9074

File tree

18 files changed

+52
-3
lines changed

18 files changed

+52
-3
lines changed

Aquality.Selenium/src/Aquality.Selenium/Aquality.Selenium.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
<RepositoryType>git</RepositoryType>
1515
<PackageTags>selenium webdriver browser automation</PackageTags>
1616
<PackageLicenseFile>LICENSE</PackageLicenseFile>
17-
<Copyright>Copyright 2022 Aquality Automation</Copyright>
17+
<Copyright>Copyright 2023 Aquality Automation</Copyright>
1818
<IsPackable>true</IsPackable>
1919
</PropertyGroup>
2020

Aquality.Selenium/src/Aquality.Selenium/Configurations/WebDriverSettings/ChromeSettings.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ public override DriverOptions DriverOptions
3232
SetChromeArguments(options);
3333
SetChromeExcludedArguments(options);
3434
SetPageLoadStrategy(options);
35+
SetLoggingPreferences(options);
3536
return options;
3637
}
3738
}

Aquality.Selenium/src/Aquality.Selenium/Configurations/WebDriverSettings/DriverSettings.cs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ public abstract class DriverSettings : IDriverSettings
1717
{
1818
private IReadOnlyDictionary<string, object> options;
1919
private IReadOnlyDictionary<string, object> capabilities;
20+
private IReadOnlyDictionary<string, LogLevel> loggingPreferences;
2021
private IReadOnlyList<string> startArguments;
2122
private IReadOnlyList<string> excludedArguments;
2223

@@ -91,6 +92,24 @@ protected IReadOnlyDictionary<string, object> BrowserOptions
9192
}
9293
}
9394

95+
protected IReadOnlyDictionary<string, LogLevel> LoggingPreferences
96+
{
97+
get
98+
{
99+
if (loggingPreferences == null)
100+
{
101+
loggingPreferences = SettingsFile.GetValueDictionaryOrEmpty<LogLevel>($"{DriverSettingsPath}.{nameof(loggingPreferences)}");
102+
if (loggingPreferences.Any())
103+
{
104+
AqualityServices.LocalizedLogger.Debug("loc.browser.loggingPreferences",
105+
args: string.Join(",", loggingPreferences.Select(opt => $"{Environment.NewLine}{opt.Key}: {opt.Value}")));
106+
}
107+
}
108+
109+
return loggingPreferences;
110+
}
111+
}
112+
94113
protected IReadOnlyList<string> BrowserExcludedArguments
95114
{
96115
get
@@ -159,6 +178,14 @@ protected void SetCapabilities(DriverOptions options, Action<string, object> add
159178
}
160179
}
161180

181+
protected void SetLoggingPreferences(DriverOptions options)
182+
{
183+
foreach (var preference in LoggingPreferences)
184+
{
185+
options.SetLoggingPreference(preference.Key, preference.Value);
186+
}
187+
}
188+
162189
private void SetKnownProperty(DriverOptions options, KeyValuePair<string, object> capability, ArgumentException exception)
163190
{
164191
if (KnownCapabilitySetters.ContainsKey(capability.Key))

Aquality.Selenium/src/Aquality.Selenium/Configurations/WebDriverSettings/EdgeSettings.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ public override DriverOptions DriverOptions
3232
SetEdgeArguments(options);
3333
SetEdgeExcludedArguments(options);
3434
SetPageLoadStrategy(options);
35+
SetLoggingPreferences(options);
3536
return options;
3637
}
3738
}

Aquality.Selenium/src/Aquality.Selenium/Configurations/WebDriverSettings/FirefoxSettings.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ public override DriverOptions DriverOptions
4242
SetFirefoxPrefs(options);
4343
SetFirefoxArguments(options);
4444
SetPageLoadStrategy(options);
45+
SetLoggingPreferences(options);
4546
return options;
4647
}
4748
}

Aquality.Selenium/src/Aquality.Selenium/Configurations/WebDriverSettings/InternetExplorerSettings.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ public override DriverOptions DriverOptions
3838
SetCapabilities(options);
3939
SetOptionsByPropertyNames(options);
4040
SetPageLoadStrategy(options);
41+
SetLoggingPreferences(options);
4142
options.BrowserCommandLineArguments = string.Join(" ", BrowserStartArguments);
4243
return options;
4344
}

Aquality.Selenium/src/Aquality.Selenium/Configurations/WebDriverSettings/SafariSettings.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ public override DriverOptions DriverOptions
2828
SetCapabilities(options);
2929
SetOptionsByPropertyNames(options);
3030
SetPageLoadStrategy(options);
31+
SetLoggingPreferences(options);
3132
return options;
3233
}
3334
}

Aquality.Selenium/src/Aquality.Selenium/Resources/Localization/be.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"loc.browser.forward": "Пераходзім да наступнай старонкі",
66
"loc.browser.capabilities": "Атрымалі capabilities браўзэра з settings файла: {0}",
77
"loc.browser.options": "Атрымалі опцыі профіля браўзэра з settings файла: {0}",
8+
"loc.browser.loggingPreferences": "Атрымалі налады лагавання браўзэра з settings файла: {0}",
89
"loc.browser.driver.quit": "Закрываем браўзэр",
910
"loc.browser.getUrl": "Атрымліваем адрас бягучай старонкі",
1011
"loc.browser.url.value": "Адрас бягучай старонкі: [{0}]",

Aquality.Selenium/src/Aquality.Selenium/Resources/Localization/en.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"loc.browser.forward": "Proceed to the next page",
66
"loc.browser.capabilities": "Got browser capabilities from settings file: {0}",
77
"loc.browser.options": "Got browser profile options from settings file: {0}",
8+
"loc.browser.loggingPreferences": "Got browser logging preferences from settings file: {0}",
89
"loc.browser.driver.quit": "Closing browser",
910
"loc.browser.getUrl": "Getting current URL",
1011
"loc.browser.url.value": "Current URL: [{0}]",

Aquality.Selenium/src/Aquality.Selenium/Resources/Localization/pl.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"loc.browser.forward": "Przejście do następnej strony",
66
"loc.browser.capabilities": "Pobrano możliwości przeglądarki z pliku ustawień: {0}",
77
"loc.browser.options": "Pobrano opcje profilu przeglądarki z pliku ustawień: {0}",
8+
"loc.browser.loggingPreferences": "Pobrano ustawienia logowania przeglądarki z pliku ustawień: {0}",
89
"loc.browser.driver.quit": "Zamykanie przeglądarki",
910
"loc.browser.getUrl": "Pobieranie aktualnego adresu URL",
1011
"loc.browser.url.value": "Aktualny adres URL: [{0}]",

0 commit comments

Comments
 (0)