Skip to content

Commit

Permalink
[rb] implement chromium classes for chrome and edge to inherit
Browse files Browse the repository at this point in the history
  • Loading branch information
titusfortner committed Dec 24, 2022
1 parent 8f9abf5 commit aadd087
Show file tree
Hide file tree
Showing 18 changed files with 655 additions and 454 deletions.
1 change: 1 addition & 0 deletions rb/lib/selenium/webdriver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ module WebDriver
Location = Struct.new(:latitude, :longitude, :altitude)

autoload :BiDi, 'selenium/webdriver/bidi'
autoload :Chromium, 'selenium/webdriver/chromium'
autoload :Chrome, 'selenium/webdriver/chrome'
autoload :DevTools, 'selenium/webdriver/devtools'
autoload :Edge, 'selenium/webdriver/edge'
Expand Down
33 changes: 3 additions & 30 deletions rb/lib/selenium/webdriver/chrome/driver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
# specific language governing permissions and limitations
# under the License.

require 'selenium/webdriver/chromium/driver'

module Selenium
module WebDriver
module Chrome
Expand All @@ -26,45 +28,16 @@ module Chrome
# @api private
#

class Driver < WebDriver::Driver
EXTENSIONS = [DriverExtensions::HasCDP,
DriverExtensions::HasBiDi,
DriverExtensions::HasCasting,
DriverExtensions::HasNetworkConditions,
DriverExtensions::HasNetworkInterception,
DriverExtensions::HasWebStorage,
DriverExtensions::HasLaunching,
DriverExtensions::HasLocation,
DriverExtensions::HasPermissions,
DriverExtensions::DownloadsFiles,
DriverExtensions::HasDevTools,
DriverExtensions::HasAuthentication,
DriverExtensions::HasLogs,
DriverExtensions::HasLogEvents,
DriverExtensions::HasPinnedScripts,
DriverExtensions::PrintsPage].freeze

class Driver < Chromium::Driver
def browser
:chrome
end

private

def devtools_url
uri = URI(devtools_address)
response = Net::HTTP.get(uri.hostname, '/json/version', uri.port)

JSON.parse(response)['webSocketDebuggerUrl']
end

def devtools_version
Integer(capabilities.browser_version.split('.').first)
end

def devtools_address
"http://#{capabilities['goog:chromeOptions']['debuggerAddress']}"
end

end # Driver
end # Chrome
end # WebDriver
Expand Down
78 changes: 6 additions & 72 deletions rb/lib/selenium/webdriver/chrome/features.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,93 +17,27 @@
# specific language governing permissions and limitations
# under the License.

require 'selenium/webdriver/chromium/features'

module Selenium
module WebDriver
module Chrome
module Features

include WebDriver::Chromium::Features

CHROME_COMMANDS = {
launch_app: [:post, 'session/:session_id/chromium/launch_app'],
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'],
start_cast_desktop_mirroring: [:post, 'session/:session_id/goog/cast/start_desktop_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'],
delete_network_conditions: [:delete, 'session/:session_id/chromium/network_conditions'],
set_permission: [:post, 'session/:session_id/permissions'],
send_command: [:post, 'session/:session_id/goog/cdp/execute'],
get_available_log_types: [:get, 'session/:session_id/se/log/types'],
get_log: [:post, 'session/:session_id/se/log']
send_command: [:post, 'session/:session_id/goog/cdp/execute']
}.freeze

def commands(command)
CHROME_COMMANDS[command] || self.class::COMMANDS[command]
end

def launch_app(id)
execute :launch_app, {}, {id: id}
end

def cast_sinks
execute :get_cast_sinks
end

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 start_cast_desktop_mirroring(name)
execute :start_cast_desktop_mirroring, {}, {sinkName: name}
end

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

def set_permission(name, value)
execute :set_permission, {}, {descriptor: {name: name}, state: value}
end

def network_conditions
execute :get_network_conditions
end

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

def delete_network_conditions
execute :delete_network_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)
end

def log(type)
data = execute :get_log, {}, {type: type.to_s}

Array(data).map do |l|
LogEntry.new l.fetch('level', 'UNKNOWN'), l.fetch('timestamp'), l.fetch('message')
rescue KeyError
next
end
CHROME_COMMANDS[command] || CHROMIUM_COMMANDS[command] || self.class::COMMANDS[command]
end
end # Bridge
end # Chrome
Expand Down
Loading

0 comments on commit aadd087

Please sign in to comment.