18
18
19
19
using System ;
20
20
using System . Collections . Generic ;
21
+ using System . Globalization ;
21
22
using System . IO ;
22
23
using OpenQA . Selenium . DevTools ;
23
24
using OpenQA . Selenium . Remote ;
@@ -71,6 +72,7 @@ public class FirefoxDriver : WebDriver, IDevTools
71
72
private const int FirefoxDevToolsProtocolVersion = 85 ;
72
73
private const string FirefoxDevToolsCapabilityName = "moz:debuggerAddress" ;
73
74
private const string SetContextCommand = "setContext" ;
75
+ private const string GetContextCommand = "getContext" ;
74
76
private const string InstallAddOnCommand = "installAddOn" ;
75
77
private const string UninstallAddOnCommand = "uninstallAddOn" ;
76
78
private const string GetFullPageScreenshotCommand = "fullPageScreenshot" ;
@@ -157,6 +159,7 @@ public FirefoxDriver(FirefoxDriverService service, FirefoxOptions options, TimeS
157
159
{
158
160
// Add the custom commands unique to Firefox
159
161
this . AddCustomFirefoxCommand ( SetContextCommand , HttpCommandInfo . PostCommand , "/session/{sessionId}/moz/context" ) ;
162
+ this . AddCustomFirefoxCommand ( GetContextCommand , HttpCommandInfo . GetCommand , "/session/{sessionId}/moz/context" ) ;
160
163
this . AddCustomFirefoxCommand ( InstallAddOnCommand , HttpCommandInfo . PostCommand , "/session/{sessionId}/moz/addon/install" ) ;
161
164
this . AddCustomFirefoxCommand ( UninstallAddOnCommand , HttpCommandInfo . PostCommand , "/session/{sessionId}/moz/addon/uninstall" ) ;
162
165
this . AddCustomFirefoxCommand ( GetFullPageScreenshotCommand , HttpCommandInfo . GetCommand , "/session/{sessionId}/moz/screenshot/full" ) ;
@@ -178,6 +181,25 @@ public override IFileDetector FileDetector
178
181
set { }
179
182
}
180
183
184
+ /// <summary>
185
+ /// Sets the command context used when issuing commands to geckodriver.
186
+ /// </summary>
187
+ /// <exception cref="WebDriverException">If response is not recognized</exception>
188
+ /// <returns>The context of commands.</returns>
189
+ public FirefoxCommandContext GetContext ( )
190
+ {
191
+ FirefoxCommandContext output ;
192
+ string response = this . Execute ( GetContextCommand , null ) . Value . ToString ( ) ;
193
+
194
+ bool success = Enum . TryParse < FirefoxCommandContext > ( response , true , out output ) ;
195
+ if ( ! success )
196
+ {
197
+ throw new WebDriverException ( string . Format ( CultureInfo . InvariantCulture , "Do not recognize response: {0}; expected Context or Chrome" ) ) ;
198
+ }
199
+
200
+ return output ;
201
+ }
202
+
181
203
/// <summary>
182
204
/// Sets the command context used when issuing commands to geckodriver.
183
205
/// </summary>
@@ -187,7 +209,7 @@ public void SetContext(FirefoxCommandContext context)
187
209
string contextValue = context . ToString ( ) . ToLowerInvariant ( ) ;
188
210
Dictionary < string , object > parameters = new Dictionary < string , object > ( ) ;
189
211
parameters [ "context" ] = contextValue ;
190
- Response response = this . Execute ( SetContextCommand , parameters ) ;
212
+ this . Execute ( SetContextCommand , parameters ) ;
191
213
}
192
214
193
215
/// <summary>
0 commit comments