diff --git a/dotnet/src/webdriver/Chrome/ChromeDriver.cs b/dotnet/src/webdriver/Chrome/ChromeDriver.cs index 7d1d6ba0ffae1..9f9e96c2c3948 100644 --- a/dotnet/src/webdriver/Chrome/ChromeDriver.cs +++ b/dotnet/src/webdriver/Chrome/ChromeDriver.cs @@ -138,6 +138,7 @@ public ChromeDriver(ChromeDriverService service, ChromeOptions options) public ChromeDriver(ChromeDriverService service, ChromeOptions options, TimeSpan commandTimeout) : base(service, options, commandTimeout) { + this.AddCustomChromeCommand(ExecuteCdp, HttpCommandInfo.PostCommand, "/session/{sessionId}/goog/cdp/execute"); } } diff --git a/dotnet/src/webdriver/Chromium/ChromiumDriver.cs b/dotnet/src/webdriver/Chromium/ChromiumDriver.cs index 5a89bce81dfe5..957bc94dcfe47 100644 --- a/dotnet/src/webdriver/Chromium/ChromiumDriver.cs +++ b/dotnet/src/webdriver/Chromium/ChromiumDriver.cs @@ -43,6 +43,7 @@ public abstract class ChromiumDriver : WebDriver, ISupportsLogs, IDevTools private const string DeleteNetworkConditionsCommand = "deleteNetworkConditions"; private const string SendChromeCommand = "sendChromeCommand"; private const string SendChromeCommandWithResult = "sendChromeCommandWithResult"; + protected const string ExecuteCdp = "executeCdpCommand"; private readonly string optionsCapabilityName; private DevToolsSession devToolsSession; @@ -128,11 +129,12 @@ public ChromiumNetworkConditions NetworkConditions } /// - /// Executes a custom Chrome command. + /// Executes a custom Chrome Dev Tools Protocol Command. /// /// Name of the command to execute. /// Parameters of the command to execute. - public void ExecuteChromeCommand(string commandName, Dictionary commandParameters) + /// An object representing the result of the command, if applicable. + public object ExecuteCdpCommand(string commandName, Dictionary commandParameters) { if (commandName == null) { @@ -142,7 +144,19 @@ public void ExecuteChromeCommand(string commandName, Dictionary Dictionary parameters = new Dictionary(); parameters["cmd"] = commandName; parameters["params"] = commandParameters; - this.Execute(SendChromeCommand, parameters); + Response response = this.Execute(ExecuteCdp, parameters); + return response.Value; + } + + /// + /// Executes a custom Chrome command. + /// + /// Name of the command to execute. + /// Parameters of the command to execute. + [Obsolete("ExecuteChromeCommand is deprecated in favor of ExecuteCdpCommand.")] + public void ExecuteChromeCommand(string commandName, Dictionary commandParameters) + { + ExecuteCdpCommand(commandName, commandParameters); } /// @@ -151,18 +165,10 @@ public void ExecuteChromeCommand(string commandName, Dictionary /// Name of the command to execute. /// Parameters of the command to execute. /// An object representing the result of the command. + [Obsolete("ExecuteChromeCommandWithResult is deprecated in favor of ExecuteCdpCommand.")] public object ExecuteChromeCommandWithResult(string commandName, Dictionary commandParameters) { - if (commandName == null) - { - throw new ArgumentNullException("commandName", "commandName must not be null"); - } - - Dictionary parameters = new Dictionary(); - parameters["cmd"] = commandName; - parameters["params"] = commandParameters; - Response response = this.Execute(SendChromeCommandWithResult, parameters); - return response.Value; + return ExecuteCdpCommand(commandName, commandParameters); } /// @@ -248,7 +254,7 @@ private static ICapabilities ConvertOptionsToCapabilities(ChromiumOptions option return options.ToCapabilities(); } - private void AddCustomChromeCommand(string commandName, string method, string resourcePath) + protected void AddCustomChromeCommand(string commandName, string method, string resourcePath) { HttpCommandInfo commandInfoToAdd = new HttpCommandInfo(method, resourcePath); this.CommandExecutor.TryAddCommand(commandName, commandInfoToAdd); diff --git a/dotnet/src/webdriver/Edge/EdgeDriver.cs b/dotnet/src/webdriver/Edge/EdgeDriver.cs index 1cb91dc407c70..4e95fd96bfb01 100644 --- a/dotnet/src/webdriver/Edge/EdgeDriver.cs +++ b/dotnet/src/webdriver/Edge/EdgeDriver.cs @@ -106,6 +106,7 @@ public EdgeDriver(EdgeDriverService service, EdgeOptions options) public EdgeDriver(EdgeDriverService service, EdgeOptions options, TimeSpan commandTimeout) : base(service, options, commandTimeout) { + this.AddCustomChromeCommand(ExecuteCdp, HttpCommandInfo.PostCommand, "/session/{sessionId}/ms/cdp/execute"); } } }