Skip to content

Commit

Permalink
[chromedriver] Expose chromedriver "execute CDP command" command
Browse files Browse the repository at this point in the history
  • Loading branch information
shs96c committed Apr 2, 2019
1 parent 0a59fc1 commit dea8dff
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
22 changes: 21 additions & 1 deletion java/client/src/org/openqa/selenium/chrome/ChromeDriver.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@
import org.openqa.selenium.remote.html5.RemoteWebStorage;
import org.openqa.selenium.remote.mobile.RemoteNetworkConnection;

import java.util.Map;
import java.util.Objects;

/**
* A {@link WebDriver} implementation that controls a Chrome browser running on the local machine.
* This class is provided as a convenience for easily testing the Chrome browser. The control server
Expand Down Expand Up @@ -172,7 +175,7 @@ public ChromeDriver(ChromeDriverService service, ChromeOptions options) {
* Creates a new ChromeDriver instance. The {@code service} will be started along with the
* driver, and shutdown upon calling {@link #quit()}.
*
* @param service The service to use.
* @param service The service to use.
* @param capabilities The capabilities required from the ChromeDriver.
* @deprecated Use {@link ChromeDriver(ChromeDriverService, ChromeOptions)} instead.
*/
Expand Down Expand Up @@ -236,4 +239,21 @@ public void launchApp(String id) {
execute(ChromeDriverCommand.LAUNCH_APP, ImmutableMap.of("id", id));
}

/**
* Execute a Chrome Devtools Protocol command and get returned result. The
* command and command args should follow
* <a href="https://chromedevtools.github.io/devtools-protocol/">chrome
* devtools protocol domains/commands</a>.
*/
public Map<String, Object> executeCdpCommand(String commandName, Map<String, Object> parameters) {
Objects.requireNonNull(commandName, "Command name must be set.");
Objects.requireNonNull(parameters, "Parameters for command must be set.");

@SuppressWarnings("unchecked")
Map<String, Object> toReturn = (Map<String, Object>) getExecuteMethod().execute(
ChromeDriverCommand.EXECUTE_CDP_COMMAND,
ImmutableMap.of("cmd", commandName, "params", parameters));

return ImmutableMap.copyOf(toReturn);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,5 @@ private ChromeDriverCommand() {}
static final String GET_NETWORK_CONDITIONS = "getNetworkConditions";
static final String SET_NETWORK_CONDITIONS = "setNetworkConditions";
static final String DELETE_NETWORK_CONDITIONS = "deleteNetworkConditions";
static final String EXECUTE_CDP_COMMAND = "executeCdpCommand";
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@ class ChromeDriverCommandExecutor extends DriverCommandExecutor {
ChromeDriverCommand.SET_NETWORK_CONDITIONS,
new CommandInfo("/session/:sessionId/chromium/network_conditions", HttpMethod.POST),
ChromeDriverCommand.DELETE_NETWORK_CONDITIONS,
new CommandInfo("/session/:sessionId/chromium/network_conditions", HttpMethod.DELETE)
);
new CommandInfo("/session/:sessionId/chromium/network_conditions", HttpMethod.DELETE),
ChromeDriverCommand.EXECUTE_CDP_COMMAND,
new CommandInfo("/session/:sessionId/goog/cdp/execute", HttpMethod.POST));

public ChromeDriverCommandExecutor(DriverService service) {
super(service, CHROME_COMMAND_NAME_TO_URL);
Expand Down

0 comments on commit dea8dff

Please sign in to comment.