diff --git a/dotnet/src/webdriver/Firefox/FirefoxDriver.cs b/dotnet/src/webdriver/Firefox/FirefoxDriver.cs index 039ac27fa0529..653030ca17cc4 100644 --- a/dotnet/src/webdriver/Firefox/FirefoxDriver.cs +++ b/dotnet/src/webdriver/Firefox/FirefoxDriver.cs @@ -18,6 +18,7 @@ using System; using System.Collections.Generic; +using System.Globalization; using System.IO; using OpenQA.Selenium.DevTools; using OpenQA.Selenium.Remote; @@ -71,6 +72,7 @@ public class FirefoxDriver : WebDriver, IDevTools private const int FirefoxDevToolsProtocolVersion = 85; private const string FirefoxDevToolsCapabilityName = "moz:debuggerAddress"; private const string SetContextCommand = "setContext"; + private const string GetContextCommand = "getContext"; private const string InstallAddOnCommand = "installAddOn"; private const string UninstallAddOnCommand = "uninstallAddOn"; private const string GetFullPageScreenshotCommand = "fullPageScreenshot"; @@ -157,6 +159,7 @@ public FirefoxDriver(FirefoxDriverService service, FirefoxOptions options, TimeS { // Add the custom commands unique to Firefox this.AddCustomFirefoxCommand(SetContextCommand, HttpCommandInfo.PostCommand, "/session/{sessionId}/moz/context"); + this.AddCustomFirefoxCommand(GetContextCommand, HttpCommandInfo.GetCommand, "/session/{sessionId}/moz/context"); this.AddCustomFirefoxCommand(InstallAddOnCommand, HttpCommandInfo.PostCommand, "/session/{sessionId}/moz/addon/install"); this.AddCustomFirefoxCommand(UninstallAddOnCommand, HttpCommandInfo.PostCommand, "/session/{sessionId}/moz/addon/uninstall"); this.AddCustomFirefoxCommand(GetFullPageScreenshotCommand, HttpCommandInfo.GetCommand, "/session/{sessionId}/moz/screenshot/full"); @@ -178,6 +181,25 @@ public override IFileDetector FileDetector set { } } + /// + /// Sets the command context used when issuing commands to geckodriver. + /// + /// If response is not recognized + /// The context of commands. + public FirefoxCommandContext GetContext() + { + FirefoxCommandContext output; + string response = this.Execute(GetContextCommand, null).Value.ToString(); + + bool success = Enum.TryParse(response, true, out output); + if (!success) + { + throw new WebDriverException(string.Format(CultureInfo.InvariantCulture, "Do not recognize response: {0}; expected Context or Chrome")); + } + + return output; + } + /// /// Sets the command context used when issuing commands to geckodriver. /// @@ -187,7 +209,7 @@ public void SetContext(FirefoxCommandContext context) string contextValue = context.ToString().ToLowerInvariant(); Dictionary parameters = new Dictionary(); parameters["context"] = contextValue; - Response response = this.Execute(SetContextCommand, parameters); + this.Execute(SetContextCommand, parameters); } ///