Skip to content

Commit 36b7559

Browse files
#66 Fill template variables of driver options capabilities and preferences
1 parent 48b8b86 commit 36b7559

File tree

5 files changed

+19
-11
lines changed

5 files changed

+19
-11
lines changed

src/Atata.Configuration.Json/Mapping/ChromeDriverJsonMapper.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ protected override void MapOptions(DriverOptionsJsonSection section, ChromeOptio
1717
if (section.GlobalAdditionalCapabilities != null)
1818
{
1919
foreach (var item in section.GlobalAdditionalCapabilities.ExtraPropertiesMap)
20-
options.AddAdditionalCapability(item.Key, item.Value, true);
20+
options.AddAdditionalCapability(item.Key, FillTemplateVariables(item.Value), true);
2121
}
2222

2323
if (section.Proxy != null)
@@ -47,13 +47,13 @@ protected override void MapOptions(DriverOptionsJsonSection section, ChromeOptio
4747
if (section.UserProfilePreferences != null)
4848
{
4949
foreach (var item in section.UserProfilePreferences.ExtraPropertiesMap)
50-
options.AddUserProfilePreference(item.Key, item.Value);
50+
options.AddUserProfilePreference(item.Key, FillTemplateVariables(item.Value));
5151
}
5252

5353
if (section.LocalStatePreferences != null)
5454
{
5555
foreach (var item in section.LocalStatePreferences.ExtraPropertiesMap)
56-
options.AddLocalStatePreference(item.Key, item.Value);
56+
options.AddLocalStatePreference(item.Key, FillTemplateVariables(item.Value));
5757
}
5858

5959
if (!string.IsNullOrWhiteSpace(section.MobileEmulationDeviceName))

src/Atata.Configuration.Json/Mapping/DriverJsonMapper`3.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ protected virtual void MapOptions(DriverOptionsJsonSection section, TOptions opt
7575
if (section.AdditionalCapabilities != null)
7676
{
7777
foreach (var item in section.AdditionalCapabilities.ExtraPropertiesMap)
78-
options.AddAdditionalCapability(item.Key, item.Value);
78+
options.AddAdditionalCapability(item.Key, FillTemplateVariables(item.Value));
7979
}
8080
}
8181

@@ -93,5 +93,13 @@ private static string FormatDriverPath(string driverPath)
9393
? driverPath.Replace(BaseDirectoryVariable, AppDomain.CurrentDomain.BaseDirectory.TrimEnd(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar))
9494
: driverPath;
9595
}
96+
97+
protected static object FillTemplateVariables(object value) =>
98+
value is string valueAsString
99+
? FillTemplateVariables(valueAsString)
100+
: value;
101+
102+
protected static string FillTemplateVariables(string value) =>
103+
AtataContext.Current?.FillTemplateString(value) ?? value;
96104
}
97105
}

src/Atata.Configuration.Json/Mapping/FirefoxDriverJsonMapper.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ protected override void MapOptions(DriverOptionsJsonSection section, FirefoxOpti
1818
if (section.GlobalAdditionalCapabilities != null)
1919
{
2020
foreach (var item in section.GlobalAdditionalCapabilities.ExtraPropertiesMap)
21-
options.AddAdditionalCapability(item.Key, item.Value, true);
21+
options.AddAdditionalCapability(item.Key, FillTemplateVariables(item.Value), true);
2222
}
2323

2424
if (section.Proxy != null)
@@ -59,7 +59,7 @@ private void SetOptionsPreference(string name, object value, FirefoxOptions opti
5959
options.SetPreference(name, castedValue);
6060
break;
6161
case string castedValue:
62-
options.SetPreference(name, castedValue);
62+
options.SetPreference(name, FillTemplateVariables(castedValue));
6363
break;
6464
case null:
6565
options.SetPreference(name, null as string);
@@ -106,7 +106,7 @@ private void SetProfilePreference(string name, object value, FirefoxProfile prof
106106
profile.SetPreference(name, castedValue);
107107
break;
108108
case string castedValue:
109-
profile.SetPreference(name, castedValue);
109+
profile.SetPreference(name, FillTemplateVariables(castedValue));
110110
break;
111111
case null:
112112
throw new ArgumentNullException(nameof(value), $"Unsupported {nameof(FirefoxProfile)} preference value: null. Supports: string, int, bool.");

src/Atata.Configuration.Json/Mapping/InternetExplorerDriverJsonMapper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ protected override void MapOptions(DriverOptionsJsonSection section, InternetExp
1616
if (section.GlobalAdditionalCapabilities != null)
1717
{
1818
foreach (var item in section.GlobalAdditionalCapabilities.ExtraPropertiesMap)
19-
options.AddAdditionalCapability(item.Key, item.Value, true);
19+
options.AddAdditionalCapability(item.Key, FillTemplateVariables(item.Value), true);
2020
}
2121

2222
if (section.Proxy != null)

src/Atata.Configuration.Json/Mapping/OperaDriverJsonMapper.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ protected override void MapOptions(DriverOptionsJsonSection section, OperaOption
1717
if (section.GlobalAdditionalCapabilities != null)
1818
{
1919
foreach (var item in section.GlobalAdditionalCapabilities.ExtraPropertiesMap)
20-
options.AddAdditionalCapability(item.Key, item.Value, true);
20+
options.AddAdditionalCapability(item.Key, FillTemplateVariables(item.Value), true);
2121
}
2222

2323
if (section.Proxy != null)
@@ -38,13 +38,13 @@ protected override void MapOptions(DriverOptionsJsonSection section, OperaOption
3838
if (section.UserProfilePreferences != null)
3939
{
4040
foreach (var item in section.UserProfilePreferences.ExtraPropertiesMap)
41-
options.AddUserProfilePreference(item.Key, item.Value);
41+
options.AddUserProfilePreference(item.Key, FillTemplateVariables(item.Value));
4242
}
4343

4444
if (section.LocalStatePreferences != null)
4545
{
4646
foreach (var item in section.LocalStatePreferences.ExtraPropertiesMap)
47-
options.AddLocalStatePreference(item.Key, item.Value);
47+
options.AddLocalStatePreference(item.Key, FillTemplateVariables(item.Value));
4848
}
4949
}
5050
}

0 commit comments

Comments
 (0)