Skip to content

Commit

Permalink
[dotnet] mark deprecated chromedriver commands as obsolete and implem…
Browse files Browse the repository at this point in the history
…ent new preferred command
  • Loading branch information
titusfortner committed Sep 28, 2021
1 parent a560c42 commit e6fb3fe
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 14 deletions.
1 change: 1 addition & 0 deletions dotnet/src/webdriver/Chrome/ChromeDriver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}

}
Expand Down
34 changes: 20 additions & 14 deletions dotnet/src/webdriver/Chromium/ChromiumDriver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -128,11 +129,12 @@ public ChromiumNetworkConditions NetworkConditions
}

/// <summary>
/// Executes a custom Chrome command.
/// Executes a custom Chrome Dev Tools Protocol Command.
/// </summary>
/// <param name="commandName">Name of the command to execute.</param>
/// <param name="commandParameters">Parameters of the command to execute.</param>
public void ExecuteChromeCommand(string commandName, Dictionary<string, object> commandParameters)
/// <returns>An object representing the result of the command, if applicable.</returns>
public object ExecuteCdpCommand(string commandName, Dictionary<string, object> commandParameters)
{
if (commandName == null)
{
Expand All @@ -142,7 +144,19 @@ public void ExecuteChromeCommand(string commandName, Dictionary<string, object>
Dictionary<string, object> parameters = new Dictionary<string, object>();
parameters["cmd"] = commandName;
parameters["params"] = commandParameters;
this.Execute(SendChromeCommand, parameters);
Response response = this.Execute(ExecuteCdp, parameters);
return response.Value;
}

/// <summary>
/// Executes a custom Chrome command.
/// </summary>
/// <param name="commandName">Name of the command to execute.</param>
/// <param name="commandParameters">Parameters of the command to execute.</param>
[Obsolete("ExecuteChromeCommand is deprecated in favor of ExecuteCdpCommand.")]
public void ExecuteChromeCommand(string commandName, Dictionary<string, object> commandParameters)
{
ExecuteCdpCommand(commandName, commandParameters);
}

/// <summary>
Expand All @@ -151,18 +165,10 @@ public void ExecuteChromeCommand(string commandName, Dictionary<string, object>
/// <param name="commandName">Name of the command to execute.</param>
/// <param name="commandParameters">Parameters of the command to execute.</param>
/// <returns>An object representing the result of the command.</returns>
[Obsolete("ExecuteChromeCommandWithResult is deprecated in favor of ExecuteCdpCommand.")]
public object ExecuteChromeCommandWithResult(string commandName, Dictionary<string, object> commandParameters)
{
if (commandName == null)
{
throw new ArgumentNullException("commandName", "commandName must not be null");
}

Dictionary<string, object> parameters = new Dictionary<string, object>();
parameters["cmd"] = commandName;
parameters["params"] = commandParameters;
Response response = this.Execute(SendChromeCommandWithResult, parameters);
return response.Value;
return ExecuteCdpCommand(commandName, commandParameters);
}

/// <summary>
Expand Down Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions dotnet/src/webdriver/Edge/EdgeDriver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}
}

0 comments on commit e6fb3fe

Please sign in to comment.