Skip to content

Instantly share code, notes, and snippets.

@jimevans
Created November 29, 2021 17:44
Show Gist options
  • Save jimevans/cf06000720a8dd5a97ed197647d030dd to your computer and use it in GitHub Desktop.
Save jimevans/cf06000720a8dd5a97ed197647d030dd to your computer and use it in GitHub Desktop.
Add custom command
// N.B., this example is far more verbose than required to showcase
// the full statements required. Production code would not need to be
// this verbose. Execution of custom commands is usually accomplished
// by subclassing the base class and having custom methods to use
// the executor to call the custom commands.
// The name of the command should be unique among command names.
string commandName = "someArbitraryUniqueCommandName";
// HttpCommandInfo can use either Get, Post, or Delete commands. The
// URL parameter is parameterized by replaceable tokens in braces.
CommandInfo commandInfo = new HttpCommandInfo(HttpCommandInfo.PostCommand, "/session/{sessionId}/whateverVendorPrefix/urlToCustomCommand");
// Assume driver is a properly instantiated IWebDriver instance
// (cast error checking omitted for brevity).
IHasCommandExecutor commandExecutorDriver = driver as IHasCommandExecutor;
commandExecutorDriver.CommandExecutor.TryAddCommand(commandName, commandInfo);
// To execute the custom command, call the Execute method with the
// parameters for your command.
Dictionary<string, object> commandParams = new Dictionary<string, object();
commandExecutorDriver.CommandExecutor.Execute(commandName, commandParams);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment