Skip to content

Commit

Permalink
Merge pull request #225 from aquality-automation/feature/support-logg…
Browse files Browse the repository at this point in the history
…ing-preferences

Support logging preferences from settings.json +semver: feature
  • Loading branch information
aqualityAutomation authored Jan 11, 2023
2 parents bf49950 + b2cf3c4 commit 66b9074
Show file tree
Hide file tree
Showing 18 changed files with 52 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<RepositoryType>git</RepositoryType>
<PackageTags>selenium webdriver browser automation</PackageTags>
<PackageLicenseFile>LICENSE</PackageLicenseFile>
<Copyright>Copyright 2022 Aquality Automation</Copyright>
<Copyright>Copyright 2023 Aquality Automation</Copyright>
<IsPackable>true</IsPackable>
</PropertyGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public override DriverOptions DriverOptions
SetChromeArguments(options);
SetChromeExcludedArguments(options);
SetPageLoadStrategy(options);
SetLoggingPreferences(options);
return options;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public abstract class DriverSettings : IDriverSettings
{
private IReadOnlyDictionary<string, object> options;
private IReadOnlyDictionary<string, object> capabilities;
private IReadOnlyDictionary<string, LogLevel> loggingPreferences;
private IReadOnlyList<string> startArguments;
private IReadOnlyList<string> excludedArguments;

Expand Down Expand Up @@ -91,6 +92,24 @@ protected IReadOnlyDictionary<string, object> BrowserOptions
}
}

protected IReadOnlyDictionary<string, LogLevel> LoggingPreferences
{
get
{
if (loggingPreferences == null)
{
loggingPreferences = SettingsFile.GetValueDictionaryOrEmpty<LogLevel>($"{DriverSettingsPath}.{nameof(loggingPreferences)}");
if (loggingPreferences.Any())
{
AqualityServices.LocalizedLogger.Debug("loc.browser.loggingPreferences",
args: string.Join(",", loggingPreferences.Select(opt => $"{Environment.NewLine}{opt.Key}: {opt.Value}")));
}
}

return loggingPreferences;
}
}

protected IReadOnlyList<string> BrowserExcludedArguments
{
get
Expand Down Expand Up @@ -159,6 +178,14 @@ protected void SetCapabilities(DriverOptions options, Action<string, object> add
}
}

protected void SetLoggingPreferences(DriverOptions options)
{
foreach (var preference in LoggingPreferences)
{
options.SetLoggingPreference(preference.Key, preference.Value);
}
}

private void SetKnownProperty(DriverOptions options, KeyValuePair<string, object> capability, ArgumentException exception)
{
if (KnownCapabilitySetters.ContainsKey(capability.Key))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public override DriverOptions DriverOptions
SetEdgeArguments(options);
SetEdgeExcludedArguments(options);
SetPageLoadStrategy(options);
SetLoggingPreferences(options);
return options;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public override DriverOptions DriverOptions
SetFirefoxPrefs(options);
SetFirefoxArguments(options);
SetPageLoadStrategy(options);
SetLoggingPreferences(options);
return options;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public override DriverOptions DriverOptions
SetCapabilities(options);
SetOptionsByPropertyNames(options);
SetPageLoadStrategy(options);
SetLoggingPreferences(options);
options.BrowserCommandLineArguments = string.Join(" ", BrowserStartArguments);
return options;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public override DriverOptions DriverOptions
SetCapabilities(options);
SetOptionsByPropertyNames(options);
SetPageLoadStrategy(options);
SetLoggingPreferences(options);
return options;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"loc.browser.forward": "Пераходзім да наступнай старонкі",
"loc.browser.capabilities": "Атрымалі capabilities браўзэра з settings файла: {0}",
"loc.browser.options": "Атрымалі опцыі профіля браўзэра з settings файла: {0}",
"loc.browser.loggingPreferences": "Атрымалі налады лагавання браўзэра з settings файла: {0}",
"loc.browser.driver.quit": "Закрываем браўзэр",
"loc.browser.getUrl": "Атрымліваем адрас бягучай старонкі",
"loc.browser.url.value": "Адрас бягучай старонкі: [{0}]",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"loc.browser.forward": "Proceed to the next page",
"loc.browser.capabilities": "Got browser capabilities from settings file: {0}",
"loc.browser.options": "Got browser profile options from settings file: {0}",
"loc.browser.loggingPreferences": "Got browser logging preferences from settings file: {0}",
"loc.browser.driver.quit": "Closing browser",
"loc.browser.getUrl": "Getting current URL",
"loc.browser.url.value": "Current URL: [{0}]",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"loc.browser.forward": "Przejście do następnej strony",
"loc.browser.capabilities": "Pobrano możliwości przeglądarki z pliku ustawień: {0}",
"loc.browser.options": "Pobrano opcje profilu przeglądarki z pliku ustawień: {0}",
"loc.browser.loggingPreferences": "Pobrano ustawienia logowania przeglądarki z pliku ustawień: {0}",
"loc.browser.driver.quit": "Zamykanie przeglądarki",
"loc.browser.getUrl": "Pobieranie aktualnego adresu URL",
"loc.browser.url.value": "Aktualny adres URL: [{0}]",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"loc.browser.forward": "Перейти на следующую страницу",
"loc.browser.capabilities": "Получили capabilities браузера из settings файла: {0}",
"loc.browser.options": "Получили опции профиля браузера из settings файла: {0}",
"loc.browser.loggingPreferences": "Получили настройки логирования браузера из settings файла: {0}",
"loc.browser.driver.quit": "Закрытие драйвера браузера",
"loc.browser.getUrl": "Получение адреса текущей страницы",
"loc.browser.url.value": "Адрес текущей страницы: [{0}]",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"loc.browser.forward": "Перехід до наступної сторінки",
"loc.browser.capabilities": "Отримані можливості браузера з файлу налаштувань: {0}",
"loc.browser.options": "Отримані параметри профілю браузера з файлу налаштувань: {0}",
"loc.browser.loggingPreferences": "Отримані налаштування логовання браузера з файлу налаштувань: {0}",
"loc.browser.driver.quit": "Закриття браузера",
"loc.browser.getUrl": "Отримання адреси поточної сторінки",
"loc.browser.url.value": "Адреса поточної сторінки: [{0}]",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
"download.prompt_for_download": "false",
"download.default_directory": "./downloads"
},
"loggingPreferences": {
"Performance": "All"
},
"excludedArguments": [ "enable-automation" ],
"startArguments": [],
"pageLoadStrategy": "Normal"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.4.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.4.1" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
"download.prompt_for_download": "false",
"download.default_directory": "./downloads"
},
"loggingPreferences": {
"Performance": "All"
},
"excludedArguments": [ "enable-automation" ],
"startArguments": [],
"pageLoadStrategy": "Normal"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
"download.prompt_for_download": "false",
"download.default_directory": "./downloads"
},
"loggingPreferences": {
"Performance": "All"
},
"excludedArguments": [ "enable-automation" ],
"startArguments": [],
"pageLoadStrategy": "Normal"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
"download.prompt_for_download": "false",
"download.default_directory": "./downloads"
},
"loggingPreferences": {
"Performance": "All"
},
"startArguments": [
"--no-sandbox",
"--headless",
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@
same "printed page" as the copyright notice for easier
identification within third-party archives.

Copyright 2022 Aquality Automation
Copyright 2023 Aquality Automation

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down

0 comments on commit 66b9074

Please sign in to comment.