Skip to content

Commit ca158e8

Browse files
authored
Add GetValueDictionaryOrEmpty method to use in sibling libraries for capabilities. (#75)
Resolves #15
1 parent 6ea110f commit ca158e8

File tree

3 files changed

+50
-0
lines changed

3 files changed

+50
-0
lines changed

Aquality.Selenium.Core/src/Aquality.Selenium.Core/Aquality.Selenium.Core.xml

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Aquality.Selenium.Core/src/Aquality.Selenium.Core/Utilities/SettingsFileExtensions.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,21 @@ public static IReadOnlyList<T> GetValueListOrEmpty<T>(this ISettingsFile file, s
3131
return file.IsValuePresent(path) ? file.GetValueList<T>(path) : new List<T>();
3232
}
3333

34+
/// <summary>
35+
/// Gets dictionary of values from environment\setting file or empty Dictionary if path doesn't exist in file and environment variables.
36+
/// Exception will not be thrown.
37+
/// Note that each value of dictionary that is present in settings file can be overriden via Environment variable with the same name;
38+
/// (e.g. for capability "safebrowsing.enabled" at dictionary path ".driverSettings.chrome.options" you can set environment variable "driverSettings.chrome.options.safebrowsing.enabled")
39+
/// </summary>
40+
/// <typeparam name="T">Type of a value.</typeparam>
41+
/// <param name="file">Settings file.</param>
42+
/// <param name="path">Path to a value. Depends on file format, it can be xpath, path etc.</param>
43+
/// <returns>Dictionary of values or empty Dictionary.</returns>
44+
public static IReadOnlyDictionary<string, T> GetValueDictionaryOrEmpty<T>(this ISettingsFile file, string path)
45+
{
46+
return file.IsValuePresent(path) ? file.GetValueDictionary<T>(path) : new Dictionary<string, T>();
47+
}
48+
3449
/// <summary>
3550
/// Gets value from environment\setting file or return default of T if path doesn't exist in file and environment variables.
3651
/// Exception will not be threw.

Aquality.Selenium.Core/tests/Aquality.Selenium.Core.Tests/Utilities/JsonFileTests.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,29 @@ public void Should_BePossibleTo_GetValueDictionary()
8282
"Dictionary of keys and values was received successively");
8383
}
8484

85+
[Test]
86+
public void Should_BePossibleTo_GetNotEmptyValueDictionary()
87+
{
88+
var expectedDict = new Dictionary<string, object>
89+
{
90+
{"intl.accept_languages", "en"},
91+
{"profile.default_content_settings.popups", "0"},
92+
{"disable-popup-blocking", "true"}
93+
};
94+
Assert.AreEqual(expectedDict,
95+
AddedParamsSettings.GetValueDictionaryOrEmpty<object>(".driverSettings.chrome.options"),
96+
"Dictionary of keys and values was received successively");
97+
}
98+
99+
[Test]
100+
public void Should_BePossibleTo_GetEmptyValueDictionary()
101+
{
102+
var expectedDict = new Dictionary<string, object>();
103+
Assert.AreEqual(expectedDict,
104+
AddedParamsSettings.GetValueDictionaryOrEmpty<object>(".some.absent.path"),
105+
"Dictionary of keys and values was not empty");
106+
}
107+
85108
[Test]
86109
[NonParallelizable]
87110
public void Should_BePossibleTo_OverrideDictionaryOfValues_FromEnvVar()

0 commit comments

Comments
 (0)