diff --git a/Aquality.Selenium.Core/src/Aquality.Selenium.Core/Aquality.Selenium.Core.xml b/Aquality.Selenium.Core/src/Aquality.Selenium.Core/Aquality.Selenium.Core.xml index dbcfe4c..065b4bf 100644 --- a/Aquality.Selenium.Core/src/Aquality.Selenium.Core/Aquality.Selenium.Core.xml +++ b/Aquality.Selenium.Core/src/Aquality.Selenium.Core/Aquality.Selenium.Core.xml @@ -957,6 +957,18 @@ Path to a value. Depends on file format, it can be xpath, path etc. List of values or empty List. + + + Gets dictionary of values from environment\setting file or empty Dictionary if path doesn't exist in file and environment variables. + Exception will not be thrown. + Note that each value of dictionary that is present in settings file can be overriden via Environment variable with the same name; + (e.g. for capability "safebrowsing.enabled" at dictionary path ".driverSettings.chrome.options" you can set environment variable "driverSettings.chrome.options.safebrowsing.enabled") + + Type of a value. + Settings file. + Path to a value. Depends on file format, it can be xpath, path etc. + Dictionary of values or empty Dictionary. + Gets value from environment\setting file or return default of T if path doesn't exist in file and environment variables. diff --git a/Aquality.Selenium.Core/src/Aquality.Selenium.Core/Utilities/SettingsFileExtensions.cs b/Aquality.Selenium.Core/src/Aquality.Selenium.Core/Utilities/SettingsFileExtensions.cs index 979e48a..e180118 100644 --- a/Aquality.Selenium.Core/src/Aquality.Selenium.Core/Utilities/SettingsFileExtensions.cs +++ b/Aquality.Selenium.Core/src/Aquality.Selenium.Core/Utilities/SettingsFileExtensions.cs @@ -31,6 +31,21 @@ public static IReadOnlyList GetValueListOrEmpty(this ISettingsFile file, s return file.IsValuePresent(path) ? file.GetValueList(path) : new List(); } + /// + /// Gets dictionary of values from environment\setting file or empty Dictionary if path doesn't exist in file and environment variables. + /// Exception will not be thrown. + /// Note that each value of dictionary that is present in settings file can be overriden via Environment variable with the same name; + /// (e.g. for capability "safebrowsing.enabled" at dictionary path ".driverSettings.chrome.options" you can set environment variable "driverSettings.chrome.options.safebrowsing.enabled") + /// + /// Type of a value. + /// Settings file. + /// Path to a value. Depends on file format, it can be xpath, path etc. + /// Dictionary of values or empty Dictionary. + public static IReadOnlyDictionary GetValueDictionaryOrEmpty(this ISettingsFile file, string path) + { + return file.IsValuePresent(path) ? file.GetValueDictionary(path) : new Dictionary(); + } + /// /// Gets value from environment\setting file or return default of T if path doesn't exist in file and environment variables. /// Exception will not be threw. diff --git a/Aquality.Selenium.Core/tests/Aquality.Selenium.Core.Tests/Utilities/JsonFileTests.cs b/Aquality.Selenium.Core/tests/Aquality.Selenium.Core.Tests/Utilities/JsonFileTests.cs index d6b109e..fc363d7 100644 --- a/Aquality.Selenium.Core/tests/Aquality.Selenium.Core.Tests/Utilities/JsonFileTests.cs +++ b/Aquality.Selenium.Core/tests/Aquality.Selenium.Core.Tests/Utilities/JsonFileTests.cs @@ -82,6 +82,29 @@ public void Should_BePossibleTo_GetValueDictionary() "Dictionary of keys and values was received successively"); } + [Test] + public void Should_BePossibleTo_GetNotEmptyValueDictionary() + { + var expectedDict = new Dictionary + { + {"intl.accept_languages", "en"}, + {"profile.default_content_settings.popups", "0"}, + {"disable-popup-blocking", "true"} + }; + Assert.AreEqual(expectedDict, + AddedParamsSettings.GetValueDictionaryOrEmpty(".driverSettings.chrome.options"), + "Dictionary of keys and values was received successively"); + } + + [Test] + public void Should_BePossibleTo_GetEmptyValueDictionary() + { + var expectedDict = new Dictionary(); + Assert.AreEqual(expectedDict, + AddedParamsSettings.GetValueDictionaryOrEmpty(".some.absent.path"), + "Dictionary of keys and values was not empty"); + } + [Test] [NonParallelizable] public void Should_BePossibleTo_OverrideDictionaryOfValues_FromEnvVar()