Skip to content

Commit

Permalink
[rb] implement chromium casting functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
titusfortner committed Sep 24, 2021
1 parent 677b1ec commit 2e3c429
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 4 deletions.
1 change: 1 addition & 0 deletions rb/lib/selenium/webdriver/chrome/driver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ module Chrome

class Driver < WebDriver::Driver
EXTENSIONS = [DriverExtensions::HasCDP,
DriverExtensions::HasCasting,
DriverExtensions::HasNetworkConditions,
DriverExtensions::HasNetworkInterception,
DriverExtensions::HasWebStorage,
Expand Down
33 changes: 29 additions & 4 deletions rb/lib/selenium/webdriver/chrome/features.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ module Chrome
module Features

CHROME_COMMANDS = {
get_cast_sinks: [:get, 'session/:session_id/goog/cast/get_sinks'],
set_cast_sink_to_use: [:post, 'session/:session_id/goog/cast/set_sink_to_use'],
start_cast_tab_mirroring: [:post, 'session/:session_id/goog/cast/start_tab_mirroring'],
get_cast_issue_message: [:get, 'session/:session_id/goog/cast/get_issue_message'],
stop_casting: [:post, 'session/:session_id/goog/cast/stop_casting'],
get_network_conditions: [:get, 'session/:session_id/chromium/network_conditions'],
set_network_conditions: [:post, 'session/:session_id/chromium/network_conditions'],
send_command: [:post, 'session/:session_id/goog/cdp/execute'],
Expand All @@ -34,18 +39,38 @@ def commands(command)
CHROME_COMMANDS[command] || self.class::COMMANDS[command]
end

def network_conditions
execute :get_network_conditions
def cast_sinks
execute :get_cast_sinks
end

def send_command(command_params)
execute :send_command, {}, command_params
def cast_sink_to_use=(name)
execute :set_cast_sink_to_use, {}, {'sinkName' => name}
end

def cast_issue_message
execute :cast_issue_message
end

def start_cast_tab_mirroring(name)
execute :start_cast_tab_mirroring, {}, {'sinkName' => name}
end

def stop_casting(name)
execute :stop_casting, {}, {'sinkName' => name}
end

def network_conditions
execute :get_network_conditions
end

def network_conditions=(conditions)
execute :set_network_conditions, {}, {network_conditions: conditions}
end

def send_command(command_params)
execute :send_command, {}, command_params
end

def available_log_types
types = execute :get_available_log_types
Array(types).map(&:to_sym)
Expand Down
1 change: 1 addition & 0 deletions rb/lib/selenium/webdriver/common.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
require 'selenium/webdriver/common/driver_extensions/has_log_events'
require 'selenium/webdriver/common/driver_extensions/has_pinned_scripts'
require 'selenium/webdriver/common/driver_extensions/has_cdp'
require 'selenium/webdriver/common/driver_extensions/has_casting'
require 'selenium/webdriver/common/keys'
require 'selenium/webdriver/common/profile_helper'
require 'selenium/webdriver/common/options'
Expand Down
5 changes: 5 additions & 0 deletions rb/lib/selenium/webdriver/edge/features.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ module Features
include WebDriver::Chrome::Features

EDGE_COMMANDS = {
get_cast_sinks: [:get, 'session/:session_id/ms/cast/get_sinks'],
set_cast_sink_to_use: [:post, 'session/:session_id/ms/cast/set_sink_to_use'],
start_cast_tab_mirroring: [:post, 'session/:session_id/ms/cast/start_tab_mirroring'],
get_cast_issue_message: [:get, 'session/:session_id/ms/cast/get_issue_message'],
stop_casting: [:post, 'session/:session_id/ms/cast/stop_casting'],
send_command: [:post, 'session/:session_id/ms/cdp/execute']
}.freeze

Expand Down
13 changes: 13 additions & 0 deletions rb/spec/integration/selenium/webdriver/chrome/driver_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,19 @@ module Chrome
expect(entries.first).to be_kind_of(LogEntry)
end
end

# This requires cast sinks to run
it 'casts' do
# Does not get list correctly the first time for some reason
driver.cast_sinks
sleep 2
sinks = driver.cast_sinks
unless sinks.empty?
device_name = sinks.first['name']
driver.start_cast_tab_mirroring(device_name)
driver.stop_casting(device_name)
end
end
end
end # Chrome
end # WebDriver
Expand Down
13 changes: 13 additions & 0 deletions rb/spec/integration/selenium/webdriver/edge/driver_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,19 @@ module Edge
expect(entries.first).to be_kind_of(LogEntry)
end
end

# This requires cast sinks to run
it 'casts' do
# Does not get list correctly the first time for some reason
driver.cast_sinks
sleep 2
sinks = driver.cast_sinks
unless sinks.empty?
device_name = sinks.first['name']
driver.start_cast_tab_mirroring(device_name)
driver.stop_casting(device_name)
end
end
end
end # Edge
end # WebDriver
Expand Down

0 comments on commit 2e3c429

Please sign in to comment.