Skip to content

Commit 2e3c429

Browse files
committed
[rb] implement chromium casting functionality
1 parent 677b1ec commit 2e3c429

File tree

6 files changed

+62
-4
lines changed

6 files changed

+62
-4
lines changed

rb/lib/selenium/webdriver/chrome/driver.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ module Chrome
2828

2929
class Driver < WebDriver::Driver
3030
EXTENSIONS = [DriverExtensions::HasCDP,
31+
DriverExtensions::HasCasting,
3132
DriverExtensions::HasNetworkConditions,
3233
DriverExtensions::HasNetworkInterception,
3334
DriverExtensions::HasWebStorage,

rb/lib/selenium/webdriver/chrome/features.rb

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ module Chrome
2323
module Features
2424

2525
CHROME_COMMANDS = {
26+
get_cast_sinks: [:get, 'session/:session_id/goog/cast/get_sinks'],
27+
set_cast_sink_to_use: [:post, 'session/:session_id/goog/cast/set_sink_to_use'],
28+
start_cast_tab_mirroring: [:post, 'session/:session_id/goog/cast/start_tab_mirroring'],
29+
get_cast_issue_message: [:get, 'session/:session_id/goog/cast/get_issue_message'],
30+
stop_casting: [:post, 'session/:session_id/goog/cast/stop_casting'],
2631
get_network_conditions: [:get, 'session/:session_id/chromium/network_conditions'],
2732
set_network_conditions: [:post, 'session/:session_id/chromium/network_conditions'],
2833
send_command: [:post, 'session/:session_id/goog/cdp/execute'],
@@ -34,18 +39,38 @@ def commands(command)
3439
CHROME_COMMANDS[command] || self.class::COMMANDS[command]
3540
end
3641

37-
def network_conditions
38-
execute :get_network_conditions
42+
def cast_sinks
43+
execute :get_cast_sinks
3944
end
4045

41-
def send_command(command_params)
42-
execute :send_command, {}, command_params
46+
def cast_sink_to_use=(name)
47+
execute :set_cast_sink_to_use, {}, {'sinkName' => name}
48+
end
49+
50+
def cast_issue_message
51+
execute :cast_issue_message
52+
end
53+
54+
def start_cast_tab_mirroring(name)
55+
execute :start_cast_tab_mirroring, {}, {'sinkName' => name}
56+
end
57+
58+
def stop_casting(name)
59+
execute :stop_casting, {}, {'sinkName' => name}
60+
end
61+
62+
def network_conditions
63+
execute :get_network_conditions
4364
end
4465

4566
def network_conditions=(conditions)
4667
execute :set_network_conditions, {}, {network_conditions: conditions}
4768
end
4869

70+
def send_command(command_params)
71+
execute :send_command, {}, command_params
72+
end
73+
4974
def available_log_types
5075
types = execute :get_available_log_types
5176
Array(types).map(&:to_sym)

rb/lib/selenium/webdriver/common.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
require 'selenium/webdriver/common/driver_extensions/has_log_events'
7171
require 'selenium/webdriver/common/driver_extensions/has_pinned_scripts'
7272
require 'selenium/webdriver/common/driver_extensions/has_cdp'
73+
require 'selenium/webdriver/common/driver_extensions/has_casting'
7374
require 'selenium/webdriver/common/keys'
7475
require 'selenium/webdriver/common/profile_helper'
7576
require 'selenium/webdriver/common/options'

rb/lib/selenium/webdriver/edge/features.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ module Features
2727
include WebDriver::Chrome::Features
2828

2929
EDGE_COMMANDS = {
30+
get_cast_sinks: [:get, 'session/:session_id/ms/cast/get_sinks'],
31+
set_cast_sink_to_use: [:post, 'session/:session_id/ms/cast/set_sink_to_use'],
32+
start_cast_tab_mirroring: [:post, 'session/:session_id/ms/cast/start_tab_mirroring'],
33+
get_cast_issue_message: [:get, 'session/:session_id/ms/cast/get_issue_message'],
34+
stop_casting: [:post, 'session/:session_id/ms/cast/stop_casting'],
3035
send_command: [:post, 'session/:session_id/ms/cdp/execute']
3136
}.freeze
3237

rb/spec/integration/selenium/webdriver/chrome/driver_spec.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,19 @@ module Chrome
125125
expect(entries.first).to be_kind_of(LogEntry)
126126
end
127127
end
128+
129+
# This requires cast sinks to run
130+
it 'casts' do
131+
# Does not get list correctly the first time for some reason
132+
driver.cast_sinks
133+
sleep 2
134+
sinks = driver.cast_sinks
135+
unless sinks.empty?
136+
device_name = sinks.first['name']
137+
driver.start_cast_tab_mirroring(device_name)
138+
driver.stop_casting(device_name)
139+
end
140+
end
128141
end
129142
end # Chrome
130143
end # WebDriver

rb/spec/integration/selenium/webdriver/edge/driver_spec.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,19 @@ module Edge
8989
expect(entries.first).to be_kind_of(LogEntry)
9090
end
9191
end
92+
93+
# This requires cast sinks to run
94+
it 'casts' do
95+
# Does not get list correctly the first time for some reason
96+
driver.cast_sinks
97+
sleep 2
98+
sinks = driver.cast_sinks
99+
unless sinks.empty?
100+
device_name = sinks.first['name']
101+
driver.start_cast_tab_mirroring(device_name)
102+
driver.stop_casting(device_name)
103+
end
104+
end
92105
end
93106
end # Edge
94107
end # WebDriver

0 commit comments

Comments
 (0)