Skip to content

Commit 35f4627

Browse files
justinwoolleyshs96c
authored andcommitted
Add js bindings for chromedriver cast functionality
Cast/MediaRouter APIs for are Chromium-specific, but not Chrome-specific, so they're now in the appropriate module.
1 parent ee15b26 commit 35f4627

File tree

1 file changed

+90
-0
lines changed

1 file changed

+90
-0
lines changed

javascript/node/selenium-webdriver/chrome.js

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,11 @@ const Command = {
161161
GET_NETWORK_CONDITIONS: 'getNetworkConditions',
162162
SET_NETWORK_CONDITIONS: 'setNetworkConditions',
163163
SEND_DEVTOOLS_COMMAND: 'sendDevToolsCommand',
164+
GET_CAST_SINKS: 'getCastSinks',
165+
SET_CAST_SINK_TO_USE: 'setCastSinkToUse',
166+
START_CAST_TAB_MIRRORING: 'setCastTabMirroring',
167+
GET_CAST_ISSUE_MESSAGE: 'getCastIssueMessage',
168+
STOP_CASTING: 'stopCasting',
164169
};
165170

166171

@@ -199,6 +204,26 @@ function configureExecutor(executor) {
199204
Command.SEND_DEVTOOLS_COMMAND,
200205
'POST',
201206
'/session/:sessionId/chromium/send_command');
207+
executor.defineCommand(
208+
Command.GET_CAST_SINKS,
209+
'GET',
210+
'/session/:sessionId/goog/cast/get_sinks');
211+
executor.defineCommand(
212+
Command.SET_CAST_SINK_TO_USE,
213+
'POST',
214+
'/session/:sessionId/goog/cast/set_sink_to_use');
215+
executor.defineCommand(
216+
Command.START_CAST_TAB_MIRRORING,
217+
'POST',
218+
'/session/:sessionId/goog/cast/start_tab_mirroring');
219+
executor.defineCommand(
220+
Command.GET_CAST_ISSUE_MESSAGE,
221+
'GET',
222+
'/session/:sessionId/goog/cast/get_issue_message');
223+
executor.defineCommand(
224+
Command.STOP_CASTING,
225+
'POST',
226+
'/session/:sessionId/goog/cast/stop_casting');
202227
}
203228

204229

@@ -801,6 +826,71 @@ class Driver extends webdriver.WebDriver {
801826
'downloadPath': path
802827
});
803828
}
829+
830+
831+
/**
832+
* Returns the list of cast sinks (Cast devices) available to the Chrome media router.
833+
*
834+
* @return {!promise.Thenable<void>} A promise that will be resolved with an array of Strings
835+
* containing the friendly device names of available cast sink targets.
836+
*/
837+
getCastSinks() {
838+
return this.schedule(
839+
new command.Command(Command.GET_CAST_SINKS),
840+
'Driver.getCastSinks()');
841+
}
842+
843+
/**
844+
* Selects a cast sink (Cast device) as the recipient of media router intents (connect or play).
845+
*
846+
* @param {String} Friendly name of the target device.
847+
* @return {!promise.Thenable<void>} A promise that will be resolved
848+
* when the target device has been selected to respond further webdriver commands.
849+
*/
850+
setCastSinkToUse(deviceName) {
851+
return this.schedule(
852+
new command.Command(Command.SET_CAST_SINK_TO_USE).setParameter('sinkName', deviceName),
853+
'Driver.setCastSinkToUse(' + deviceName + ')');
854+
}
855+
856+
/**
857+
* Initiates tab mirroring for the current browser tab on the specified device.
858+
*
859+
* @param {String} Friendly name of the target device.
860+
* @return {!promise.Thenable<void>} A promise that will be resolved
861+
* when the mirror command has been issued to the device.
862+
*/
863+
startCastTabMirroring(deviceName) {
864+
return this.schedule(
865+
new command.Command(Command.START_CAST_TAB_MIRRORING).setParameter('sinkName', deviceName),
866+
'Driver.startCastTabMirroring(' + deviceName + ')');
867+
}
868+
869+
/**
870+
* a
871+
*
872+
* @param {String} Friendly name of the target device.
873+
* @return {!promise.Thenable<void>} A promise that will be resolved
874+
* when the mirror command has been issued to the device.
875+
*/
876+
getCastIssueMessage() {
877+
return this.schedule(
878+
new command.Command(Command.GET_CAST_ISSUE_MESSAGE),
879+
'Driver.getCastIssueMessage()');
880+
}
881+
882+
/**
883+
* Stops casting from media router to the specified device, if connected.
884+
*
885+
* @param {String} Friendly name of the target device.
886+
* @return {!promise.Thenable<void>} A promise that will be resolved
887+
* when the stop command has been issued to the device.
888+
*/
889+
stopCasting(deviceName) {
890+
return this.schedule(
891+
new command.Command(Command.STOP_CASTING).setParameter('sinkName', deviceName),
892+
'Driver.stopCasting(' + deviceName + ')');
893+
}
804894
}
805895

806896

0 commit comments

Comments
 (0)