@@ -58,6 +58,7 @@ public class FirefoxOptions : DriverOptions
58
58
private const string FirefoxArgumentsCapability = "args" ;
59
59
private const string FirefoxLogCapability = "log" ;
60
60
private const string FirefoxPrefsCapability = "prefs" ;
61
+ private const string FirefoxEnvCapability = "env" ;
61
62
private const string FirefoxOptionsCapability = "moz:firefoxOptions" ;
62
63
63
64
private string browserBinaryLocation ;
@@ -66,6 +67,7 @@ public class FirefoxOptions : DriverOptions
66
67
private List < string > firefoxArguments = new List < string > ( ) ;
67
68
private Dictionary < string , object > profilePreferences = new Dictionary < string , object > ( ) ;
68
69
private Dictionary < string , object > additionalFirefoxOptions = new Dictionary < string , object > ( ) ;
70
+ private Dictionary < string , object > environmentVariables = new Dictionary < string , object > ( ) ;
69
71
70
72
/// <summary>
71
73
/// Initializes a new instance of the <see cref="FirefoxOptions"/> class.
@@ -80,6 +82,7 @@ public FirefoxOptions()
80
82
this . AddKnownCapabilityName ( FirefoxOptions . FirefoxBinaryCapability , "BrowserExecutableLocation property" ) ;
81
83
this . AddKnownCapabilityName ( FirefoxOptions . FirefoxArgumentsCapability , "AddArguments method" ) ;
82
84
this . AddKnownCapabilityName ( FirefoxOptions . FirefoxPrefsCapability , "SetPreference method" ) ;
85
+ this . AddKnownCapabilityName ( FirefoxOptions . FirefoxEnvCapability , "SetEnvironmentVariable method" ) ;
83
86
this . AddKnownCapabilityName ( FirefoxOptions . FirefoxLogCapability , "LogLevel property" ) ;
84
87
this . AddKnownCapabilityName ( FirefoxOptions . FirefoxLegacyProfileCapability , "Profile property" ) ;
85
88
this . AddKnownCapabilityName ( FirefoxOptions . FirefoxLegacyBinaryCapability , "BrowserExecutableLocation property" ) ;
@@ -211,6 +214,26 @@ public void SetPreference(string preferenceName, string preferenceValue)
211
214
this . SetPreferenceValue ( preferenceName , preferenceValue ) ;
212
215
}
213
216
217
+ /// <summary>
218
+ /// Sets an environment variable to be set in the operating system's environment under which the Firerox browser is launched.
219
+ /// </summary>
220
+ /// <param name="variableName">The name of the environment variable.</param>
221
+ /// <param name="variableValue">The value of the environment variable.</param>
222
+ public void SetEnvironmentVariable ( string variableName , string variableValue )
223
+ {
224
+ if ( string . IsNullOrEmpty ( variableName ) )
225
+ {
226
+ throw new ArgumentException ( "Environment variable name cannot be null or an empty string" ) ;
227
+ }
228
+
229
+ if ( variableValue == null )
230
+ {
231
+ variableValue = string . Empty ;
232
+ }
233
+
234
+ this . environmentVariables [ variableName ] = variableValue ;
235
+ }
236
+
214
237
/// <summary>
215
238
/// Provides a means to add additional capabilities not yet added as type safe options
216
239
/// for the Firefox driver.
@@ -336,6 +359,11 @@ private Dictionary<string, object> GenerateFirefoxOptionsDictionary()
336
359
firefoxOptions [ FirefoxPrefsCapability ] = this . profilePreferences ;
337
360
}
338
361
362
+ if ( this . environmentVariables . Count > 0 )
363
+ {
364
+ firefoxOptions [ FirefoxEnvCapability ] = this . environmentVariables ;
365
+ }
366
+
339
367
foreach ( KeyValuePair < string , object > pair in this . additionalFirefoxOptions )
340
368
{
341
369
firefoxOptions . Add ( pair . Key , pair . Value ) ;
0 commit comments