Skip to content

Commit 45a06f4

Browse files
committed
[dotnet] implement getting the context of Firefox commands
1 parent 90e8e61 commit 45a06f4

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

dotnet/src/webdriver/Firefox/FirefoxDriver.cs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
using System;
2020
using System.Collections.Generic;
21+
using System.Globalization;
2122
using System.IO;
2223
using OpenQA.Selenium.DevTools;
2324
using OpenQA.Selenium.Remote;
@@ -71,6 +72,7 @@ public class FirefoxDriver : WebDriver, IDevTools
7172
private const int FirefoxDevToolsProtocolVersion = 85;
7273
private const string FirefoxDevToolsCapabilityName = "moz:debuggerAddress";
7374
private const string SetContextCommand = "setContext";
75+
private const string GetContextCommand = "getContext";
7476
private const string InstallAddOnCommand = "installAddOn";
7577
private const string UninstallAddOnCommand = "uninstallAddOn";
7678
private const string GetFullPageScreenshotCommand = "fullPageScreenshot";
@@ -157,6 +159,7 @@ public FirefoxDriver(FirefoxDriverService service, FirefoxOptions options, TimeS
157159
{
158160
// Add the custom commands unique to Firefox
159161
this.AddCustomFirefoxCommand(SetContextCommand, HttpCommandInfo.PostCommand, "/session/{sessionId}/moz/context");
162+
this.AddCustomFirefoxCommand(GetContextCommand, HttpCommandInfo.GetCommand, "/session/{sessionId}/moz/context");
160163
this.AddCustomFirefoxCommand(InstallAddOnCommand, HttpCommandInfo.PostCommand, "/session/{sessionId}/moz/addon/install");
161164
this.AddCustomFirefoxCommand(UninstallAddOnCommand, HttpCommandInfo.PostCommand, "/session/{sessionId}/moz/addon/uninstall");
162165
this.AddCustomFirefoxCommand(GetFullPageScreenshotCommand, HttpCommandInfo.GetCommand, "/session/{sessionId}/moz/screenshot/full");
@@ -178,6 +181,25 @@ public override IFileDetector FileDetector
178181
set { }
179182
}
180183

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+
181203
/// <summary>
182204
/// Sets the command context used when issuing commands to geckodriver.
183205
/// </summary>
@@ -187,7 +209,7 @@ public void SetContext(FirefoxCommandContext context)
187209
string contextValue = context.ToString().ToLowerInvariant();
188210
Dictionary<string, object> parameters = new Dictionary<string, object>();
189211
parameters["context"] = contextValue;
190-
Response response = this.Execute(SetContextCommand, parameters);
212+
this.Execute(SetContextCommand, parameters);
191213
}
192214

193215
/// <summary>

0 commit comments

Comments
 (0)