Skip to content

Commit

Permalink
Add chromedriver cast APIs to remote server (#7282)
Browse files Browse the repository at this point in the history
ChromiumDriver APIs for interacting with cast devices can now be
invoked  via calls to remote server.

Referenced ChromeDriver APIs:

https://chromium-review.googlesource.com/c/chromium/src/+/1401270
  • Loading branch information
jwoolley authored and shs96c committed Jul 12, 2019
1 parent f1526d2 commit 948837e
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 12 deletions.
22 changes: 22 additions & 0 deletions java/client/src/org/openqa/selenium/chromium/ChromiumDriver.java
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,28 @@ public DevTools getDevTools() {
.orElseThrow(() -> new WebDriverException("Unable to create DevTools connection"));
}

public String getCastSinks() {
Object response = getExecuteMethod().execute(ChromiumDriverCommand.GET_CAST_SINKS, null);
return response.toString();
}

public String getCastIssueMessage() {
Object response = getExecuteMethod().execute(ChromiumDriverCommand.GET_CAST_ISSUE_MESSAGE, null);
return response.toString();
}

public void selectCastSink(String deviceName) {
Object response = getExecuteMethod().execute(ChromiumDriverCommand.SET_CAST_SINK_TO_USE, ImmutableMap.of("sinkName", deviceName));
}

public void startTabMirroring(String deviceName) {
Object response = getExecuteMethod().execute(ChromiumDriverCommand.START_CAST_TAB_MIRRORING, ImmutableMap.of("sinkName", deviceName));
}

public void stopCasting(String deviceName) {
Object response = getExecuteMethod().execute(ChromiumDriverCommand.STOP_CASTING, ImmutableMap.of("sinkName", deviceName));
}

@Override
public void quit() {
connection.ifPresent(Connection::close);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,11 @@ private ChromiumDriverCommand() {}
static final String SET_NETWORK_CONDITIONS = "setNetworkConditions";
static final String DELETE_NETWORK_CONDITIONS = "deleteNetworkConditions";
static final String EXECUTE_CDP_COMMAND = "executeCdpCommand";

// Cast Media Router APIs
static final String GET_CAST_SINKS = "getCastSinks";
static final String SET_CAST_SINK_TO_USE = "selectCastSink";
static final String START_CAST_TAB_MIRRORING = "startCastTabMirroring";
static final String GET_CAST_ISSUE_MESSAGE = "getCastIssueMessage";
static final String STOP_CASTING = "stopCasting";
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package org.openqa.selenium.chromium;

import com.google.common.collect.ImmutableMap;
import java.util.HashMap;

import org.openqa.selenium.remote.CommandInfo;
import org.openqa.selenium.remote.http.HttpMethod;
Expand All @@ -31,19 +32,34 @@
*/
public class ChromiumDriverCommandExecutor extends DriverCommandExecutor {

private static final ImmutableMap<String, CommandInfo> CHROME_COMMAND_NAME_TO_URL = ImmutableMap.of(
ChromiumDriverCommand.LAUNCH_APP,
new CommandInfo("/session/:sessionId/chromium/launch_app", HttpMethod.POST),
ChromiumDriverCommand.GET_NETWORK_CONDITIONS,
new CommandInfo("/session/:sessionId/chromium/network_conditions", HttpMethod.GET),
ChromiumDriverCommand.SET_NETWORK_CONDITIONS,
new CommandInfo("/session/:sessionId/chromium/network_conditions", HttpMethod.POST),
ChromiumDriverCommand.DELETE_NETWORK_CONDITIONS,
new CommandInfo("/session/:sessionId/chromium/network_conditions", HttpMethod.DELETE),
ChromiumDriverCommand.EXECUTE_CDP_COMMAND,
new CommandInfo("/session/:sessionId/goog/cdp/execute", HttpMethod.POST));
private static final HashMap<String, CommandInfo> CHROME_COMMAND_NAME_TO_URL = new HashMap<String, CommandInfo>();

static {
CHROME_COMMAND_NAME_TO_URL.put(ChromiumDriverCommand.LAUNCH_APP,
new CommandInfo("/session/:sessionId/chromium/launch_app", HttpMethod.POST));
CHROME_COMMAND_NAME_TO_URL.put(ChromiumDriverCommand.GET_NETWORK_CONDITIONS,
new CommandInfo("/session/:sessionId/chromium/network_conditions", HttpMethod.GET));
CHROME_COMMAND_NAME_TO_URL.put(ChromiumDriverCommand.SET_NETWORK_CONDITIONS,
new CommandInfo("/session/:sessionId/chromium/network_conditions", HttpMethod.POST));
CHROME_COMMAND_NAME_TO_URL.put(ChromiumDriverCommand.DELETE_NETWORK_CONDITIONS,
new CommandInfo("/session/:sessionId/chromium/network_conditions", HttpMethod.DELETE));
CHROME_COMMAND_NAME_TO_URL.put( ChromiumDriverCommand.EXECUTE_CDP_COMMAND,
new CommandInfo("/session/:sessionId/goog/cdp/execute", HttpMethod.POST));

// Cast / Media Router APIs
CHROME_COMMAND_NAME_TO_URL.put(ChromiumDriverCommand.GET_CAST_SINKS,
new CommandInfo("/session/:sessionId/goog/cast/get_sinks", HttpMethod.GET));
CHROME_COMMAND_NAME_TO_URL.put(ChromiumDriverCommand.SET_CAST_SINK_TO_USE,
new CommandInfo("/session/:sessionId/goog/cast/set_sink_to_use", HttpMethod.POST));
CHROME_COMMAND_NAME_TO_URL.put(ChromiumDriverCommand.START_CAST_TAB_MIRRORING,
new CommandInfo("/session/:sessionId/goog/cast/start_tab_mirroring", HttpMethod.POST));
CHROME_COMMAND_NAME_TO_URL.put(ChromiumDriverCommand.GET_CAST_ISSUE_MESSAGE,
new CommandInfo("/session/:sessionId/goog/cast/get_issue_message", HttpMethod.GET));
CHROME_COMMAND_NAME_TO_URL.put(ChromiumDriverCommand.STOP_CASTING,
new CommandInfo("/session/:sessionId/goog/cast/stop_casting", HttpMethod.POST));
}

public ChromiumDriverCommandExecutor(DriverService service) {
super(service, CHROME_COMMAND_NAME_TO_URL);
super(service, ImmutableMap.copyOf(CHROME_COMMAND_NAME_TO_URL));
}
}

0 comments on commit 948837e

Please sign in to comment.