Skip to content

Commit

Permalink
[rb] auto load browser specific features into Bridge so they can be u…
Browse files Browse the repository at this point in the history
…sed by Remote Driver
  • Loading branch information
titusfortner committed Mar 15, 2021
1 parent fa52db0 commit 333790b
Show file tree
Hide file tree
Showing 14 changed files with 32 additions and 35 deletions.
2 changes: 1 addition & 1 deletion rb/lib/selenium/webdriver/chrome.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
module Selenium
module WebDriver
module Chrome
autoload :Bridge, 'selenium/webdriver/chrome/bridge'
autoload :Features, 'selenium/webdriver/chrome/features'
autoload :Driver, 'selenium/webdriver/chrome/driver'
autoload :Profile, 'selenium/webdriver/chrome/profile'
autoload :Options, 'selenium/webdriver/chrome/options'
Expand Down
4 changes: 0 additions & 4 deletions rb/lib/selenium/webdriver/chrome/driver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,6 @@ def browser
:chrome
end

def bridge_class
Bridge
end

def execute_cdp(cmd, **params)
@bridge.send_command(cmd: cmd, params: params)
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
module Selenium
module WebDriver
module Chrome
class Bridge < WebDriver::Remote::Bridge
module Features

COMMANDS = {
CHROME_COMMANDS = {
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 @@ -31,7 +31,7 @@ class Bridge < WebDriver::Remote::Bridge
}.freeze

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

def network_conditions
Expand Down
2 changes: 1 addition & 1 deletion rb/lib/selenium/webdriver/common/driver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ def create_bridge(**opts)
bridge_opts = {http_client: opts.delete(:http_client), url: opts.delete(:url)}
raise ArgumentError, "Unable to create a driver with parameters: #{opts}" unless opts.empty?

bridge = (respond_to?(:bridge_class) ? bridge_class : Remote::Bridge).new(**bridge_opts)
bridge = Remote::Bridge.new(**bridge_opts)

bridge.create_session(capabilities)
bridge
Expand Down
2 changes: 1 addition & 1 deletion rb/lib/selenium/webdriver/edge.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
module Selenium
module WebDriver
module Edge
autoload :Bridge, 'selenium/webdriver/edge/bridge'
autoload :Features, 'selenium/webdriver/edge/features'
autoload :Driver, 'selenium/webdriver/edge/driver'
autoload :Profile, 'selenium/webdriver/edge/profile'
autoload :Options, 'selenium/webdriver/edge/options'
Expand Down
4 changes: 0 additions & 4 deletions rb/lib/selenium/webdriver/edge/driver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,6 @@ def browser
:edge
end

def bridge_class
Bridge
end

private

def devtools_debugger_address
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,21 @@
# specific language governing permissions and limitations
# under the License.

require 'selenium/webdriver/chrome/bridge'
require 'selenium/webdriver/chrome/features'

module Selenium
module WebDriver
module Edge
class Bridge < WebDriver::Chrome::Bridge
module Features

COMMANDS = WebDriver::Chrome::Bridge::COMMANDS.merge(
include WebDriver::Chrome::Features

EDGE_COMMANDS = {
send_command: [:post, 'session/:session_id/ms/cdp/execute']
).freeze
}.freeze

def commands(command)
COMMANDS[command] || super
EDGE_COMMANDS[command] || Chrome::Features::CHROME_COMMANDS[command] || self.class::COMMANDS[command]
end
end # Bridge
end # Edge
Expand Down
2 changes: 1 addition & 1 deletion rb/lib/selenium/webdriver/firefox.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ module Firefox
autoload :Extension, 'selenium/webdriver/firefox/extension'
autoload :ProfilesIni, 'selenium/webdriver/firefox/profiles_ini'
autoload :Profile, 'selenium/webdriver/firefox/profile'
autoload :Bridge, 'selenium/webdriver/firefox/bridge'
autoload :Features, 'selenium/webdriver/firefox/features'
autoload :Driver, 'selenium/webdriver/firefox/driver'
autoload :Options, 'selenium/webdriver/firefox/options'
autoload :Service, 'selenium/webdriver/firefox/service'
Expand Down
4 changes: 0 additions & 4 deletions rb/lib/selenium/webdriver/firefox/driver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,6 @@ def browser
:firefox
end

def bridge_class
Bridge
end

private

def devtools_version
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@
module Selenium
module WebDriver
module Firefox
class Bridge < WebDriver::Remote::Bridge
module Features

COMMANDS = {
FIREFOX_COMMANDS = {
install_addon: [:post, 'session/:session_id/moz/addon/install'],
uninstall_addon: [:post, 'session/:session_id/moz/addon/uninstall']
}.freeze

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

def install_addon(path, temporary)
Expand Down
11 changes: 11 additions & 0 deletions rb/lib/selenium/webdriver/remote/bridge.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,17 @@ def create_session(capabilities)
raise Error::WebDriverError, 'no sessionId in returned payload' unless @session_id

@capabilities = Capabilities.json_create(capabilities)

case @capabilities[:browser_name]
when 'chrome'
extend(WebDriver::Chrome::Features)
when 'firefox'
extend(WebDriver::Firefox::Features)
when 'msedge'
extend(WebDriver::Edge::Features)
when 'safari'
extend(WebDriver::Safari::Features)
end
end

#
Expand Down
2 changes: 1 addition & 1 deletion rb/lib/selenium/webdriver/safari.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
module Selenium
module WebDriver
module Safari
autoload :Bridge, 'selenium/webdriver/safari/bridge'
autoload :Features, 'selenium/webdriver/safari/features'
autoload :Driver, 'selenium/webdriver/safari/driver'
autoload :Options, 'selenium/webdriver/safari/options'
autoload :Service, 'selenium/webdriver/safari/service'
Expand Down
4 changes: 0 additions & 4 deletions rb/lib/selenium/webdriver/safari/driver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,6 @@ class Driver < WebDriver::Driver
def browser
:safari
end

def bridge_class
Bridge
end
end # Driver
end # Safari
end # WebDriver
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,17 @@
module Selenium
module WebDriver
module Safari
class Bridge < WebDriver::Remote::Bridge
module Features

# https://developer.apple.com/library/content/documentation/NetworkingInternetWeb/Conceptual/WebDriverEndpointDoc/Commands/Commands.html
COMMANDS = {
SAFARI_COMMANDS = {
get_permissions: [:get, 'session/:session_id/apple/permissions'],
set_permissions: [:post, 'session/:session_id/apple/permissions'],
attach_debugger: [:post, 'session/:session_id/apple/attach_debugger']
}.freeze

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

def permissions
Expand Down

0 comments on commit 333790b

Please sign in to comment.