Skip to content

Commit 66b14c5

Browse files
authored
[java, node] Adds new desktop cast command for Chromium #10190 (#10191)
[java, node] Adds new desktop cast command for Chromium
1 parent d53d79e commit 66b14c5

6 files changed

Lines changed: 64 additions & 0 deletions

File tree

java/src/org/openqa/selenium/chrome/AddHasCasting.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ public Map<String, CommandInfo> getAdditionalCommands() {
3838
return ImmutableMap.of(
3939
GET_CAST_SINKS, new CommandInfo("session/:sessionId/goog/cast/get_sinks", HttpMethod.GET),
4040
SET_CAST_SINK_TO_USE, new CommandInfo("session/:sessionId/goog/cast/set_sink_to_use", HttpMethod.POST),
41+
START_CAST_DESKTOP_MIRRORING, new CommandInfo("session/:sessionId/goog/cast/start_desktop_mirroring", HttpMethod.POST),
4142
START_CAST_TAB_MIRRORING, new CommandInfo("session/:sessionId/goog/cast/start_tab_mirroring", HttpMethod.POST),
4243
GET_CAST_ISSUE_MESSAGE, new CommandInfo("session/:sessionId/goog/cast/get_issue_message", HttpMethod.GET),
4344
STOP_CASTING, new CommandInfo("session/:sessionId/goog/cast/stop_casting", HttpMethod.POST));

java/src/org/openqa/selenium/chromium/AddHasCasting.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ public abstract class AddHasCasting implements AugmenterProvider<HasCasting>, Ad
3434
public static final String GET_CAST_SINKS = "getCastSinks";
3535
public static final String SET_CAST_SINK_TO_USE = "selectCastSink";
3636
public static final String START_CAST_TAB_MIRRORING = "startCastTabMirroring";
37+
public static final String START_CAST_DESKTOP_MIRRORING = "startDesktopMirroring";
3738
public static final String GET_CAST_ISSUE_MESSAGE = "getCastIssueMessage";
3839
public static final String STOP_CASTING = "stopCasting";
3940

@@ -64,6 +65,13 @@ public void selectCastSink(String deviceName) {
6465
executeMethod.execute(SET_CAST_SINK_TO_USE, ImmutableMap.of("sinkName", deviceName));
6566
}
6667

68+
@Override
69+
public void startDesktopMirroring(String deviceName) {
70+
Require.nonNull("Device Name", deviceName);
71+
72+
executeMethod.execute(START_CAST_DESKTOP_MIRRORING, ImmutableMap.of("sinkName", deviceName));
73+
}
74+
6775
@Override
6876
public void startTabMirroring(String deviceName) {
6977
Require.nonNull("Device Name", deviceName);

java/src/org/openqa/selenium/chromium/ChromiumDriver.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,12 @@ public void selectCastSink(String deviceName) {
246246
casting.selectCastSink(deviceName);
247247
}
248248

249+
@Override
250+
public void startDesktopMirroring(String deviceName) {
251+
Require.nonNull("Device Name", deviceName);
252+
casting.startDesktopMirroring(deviceName);
253+
}
254+
249255
@Override
250256
public void startTabMirroring(String deviceName) {
251257
Require.nonNull("Device Name", deviceName);

java/src/org/openqa/selenium/chromium/HasCasting.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,13 @@ public interface HasCasting {
4343
*/
4444
void selectCastSink(String deviceName);
4545

46+
/**
47+
* Initiates desktop mirroring for the current browser tab on the specified device.
48+
*
49+
* @param deviceName name of the target device.
50+
*/
51+
void startDesktopMirroring(String deviceName);
52+
4653
/**
4754
* Initiates tab mirroring for the current browser tab on the specified device.
4855
*

java/test/org/openqa/selenium/chrome/ChromeDriverFunctionalTest.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,25 @@ public void canCast() throws InterruptedException {
111111
}
112112
}
113113

114+
@Test
115+
@Ignore(gitHubActions = true)
116+
public void canCastOnDesktop() throws InterruptedException {
117+
HasCasting caster = (HasCasting) driver;
118+
119+
// Does not get list the first time it is called
120+
caster.getCastSinks();
121+
Thread.sleep(1500);
122+
List<Map<String, String>> castSinks = caster.getCastSinks();
123+
124+
// Can not call these commands if there are no sinks available
125+
if (castSinks.size() > 0) {
126+
String deviceName = castSinks.get(0).get("name");
127+
128+
caster.startDesktopMirroring(deviceName);
129+
caster.stopCasting(deviceName);
130+
}
131+
}
132+
114133
@Test
115134
public void canManageNetworkConditions() {
116135
HasNetworkConditions conditions = (HasNetworkConditions) driver;

javascript/node/selenium-webdriver/chromium.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ const Command = {
9797
SET_PERMISSION: 'setPermission',
9898
GET_CAST_SINKS: 'getCastSinks',
9999
SET_CAST_SINK_TO_USE: 'setCastSinkToUse',
100+
START_CAST_DESKTOP_MIRRORING: 'startDesktopMirroring',
100101
START_CAST_TAB_MIRRORING: 'setCastTabMirroring',
101102
GET_CAST_ISSUE_MESSAGE: 'getCastIssueMessage',
102103
STOP_CASTING: 'stopCasting',
@@ -161,6 +162,11 @@ function configureExecutor(executor, vendorPrefix) {
161162
'POST',
162163
`/session/:sessionId/${vendorPrefix}/cast/set_sink_to_use`
163164
)
165+
executor.defineCommand(
166+
Command.START_CAST_DESKTOP_MIRRORING,
167+
'POST',
168+
`/session/:sessionId/${vendorPrefix}/cast/start_desktop_mirroring`
169+
)
164170
executor.defineCommand(
165171
Command.START_CAST_TAB_MIRRORING,
166172
'POST',
@@ -834,6 +840,23 @@ class Driver extends webdriver.WebDriver {
834840
)
835841
}
836842

843+
/**
844+
* Initiates desktop mirroring for the current browser tab on the specified device.
845+
*
846+
* @param {String} deviceName name of the target device.
847+
* @return {!promise.Thenable<void>} A promise that will be resolved
848+
* when the mirror command has been issued to the device.
849+
*/
850+
startDesktopMirroring(deviceName) {
851+
return this.schedule(
852+
new command.Command(Command.START_CAST_DESKTOP_MIRRORING).setParameter(
853+
'sinkName',
854+
deviceName
855+
),
856+
'Driver.startDesktopMirroring(' + deviceName + ')'
857+
)
858+
}
859+
837860
/**
838861
* Initiates tab mirroring for the current browser tab on the specified device.
839862
*

0 commit comments

Comments
 (0)