Skip to content

Commit aadd087

Browse files
committed
[rb] implement chromium classes for chrome and edge to inherit
1 parent 8f9abf5 commit aadd087

18 files changed

+655
-454
lines changed

rb/lib/selenium/webdriver.rb

+1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ module WebDriver
3636
Location = Struct.new(:latitude, :longitude, :altitude)
3737

3838
autoload :BiDi, 'selenium/webdriver/bidi'
39+
autoload :Chromium, 'selenium/webdriver/chromium'
3940
autoload :Chrome, 'selenium/webdriver/chrome'
4041
autoload :DevTools, 'selenium/webdriver/devtools'
4142
autoload :Edge, 'selenium/webdriver/edge'

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

+3-30
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
# specific language governing permissions and limitations
1818
# under the License.
1919

20+
require 'selenium/webdriver/chromium/driver'
21+
2022
module Selenium
2123
module WebDriver
2224
module Chrome
@@ -26,45 +28,16 @@ module Chrome
2628
# @api private
2729
#
2830

29-
class Driver < WebDriver::Driver
30-
EXTENSIONS = [DriverExtensions::HasCDP,
31-
DriverExtensions::HasBiDi,
32-
DriverExtensions::HasCasting,
33-
DriverExtensions::HasNetworkConditions,
34-
DriverExtensions::HasNetworkInterception,
35-
DriverExtensions::HasWebStorage,
36-
DriverExtensions::HasLaunching,
37-
DriverExtensions::HasLocation,
38-
DriverExtensions::HasPermissions,
39-
DriverExtensions::DownloadsFiles,
40-
DriverExtensions::HasDevTools,
41-
DriverExtensions::HasAuthentication,
42-
DriverExtensions::HasLogs,
43-
DriverExtensions::HasLogEvents,
44-
DriverExtensions::HasPinnedScripts,
45-
DriverExtensions::PrintsPage].freeze
46-
31+
class Driver < Chromium::Driver
4732
def browser
4833
:chrome
4934
end
5035

5136
private
5237

53-
def devtools_url
54-
uri = URI(devtools_address)
55-
response = Net::HTTP.get(uri.hostname, '/json/version', uri.port)
56-
57-
JSON.parse(response)['webSocketDebuggerUrl']
58-
end
59-
60-
def devtools_version
61-
Integer(capabilities.browser_version.split('.').first)
62-
end
63-
6438
def devtools_address
6539
"http://#{capabilities['goog:chromeOptions']['debuggerAddress']}"
6640
end
67-
6841
end # Driver
6942
end # Chrome
7043
end # WebDriver

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

+6-72
Original file line numberDiff line numberDiff line change
@@ -17,93 +17,27 @@
1717
# specific language governing permissions and limitations
1818
# under the License.
1919

20+
require 'selenium/webdriver/chromium/features'
21+
2022
module Selenium
2123
module WebDriver
2224
module Chrome
2325
module Features
2426

27+
include WebDriver::Chromium::Features
28+
2529
CHROME_COMMANDS = {
26-
launch_app: [:post, 'session/:session_id/chromium/launch_app'],
2730
get_cast_sinks: [:get, 'session/:session_id/goog/cast/get_sinks'],
2831
set_cast_sink_to_use: [:post, 'session/:session_id/goog/cast/set_sink_to_use'],
2932
start_cast_tab_mirroring: [:post, 'session/:session_id/goog/cast/start_tab_mirroring'],
3033
start_cast_desktop_mirroring: [:post, 'session/:session_id/goog/cast/start_desktop_mirroring'],
3134
get_cast_issue_message: [:get, 'session/:session_id/goog/cast/get_issue_message'],
3235
stop_casting: [:post, 'session/:session_id/goog/cast/stop_casting'],
33-
get_network_conditions: [:get, 'session/:session_id/chromium/network_conditions'],
34-
set_network_conditions: [:post, 'session/:session_id/chromium/network_conditions'],
35-
delete_network_conditions: [:delete, 'session/:session_id/chromium/network_conditions'],
36-
set_permission: [:post, 'session/:session_id/permissions'],
37-
send_command: [:post, 'session/:session_id/goog/cdp/execute'],
38-
get_available_log_types: [:get, 'session/:session_id/se/log/types'],
39-
get_log: [:post, 'session/:session_id/se/log']
36+
send_command: [:post, 'session/:session_id/goog/cdp/execute']
4037
}.freeze
4138

4239
def commands(command)
43-
CHROME_COMMANDS[command] || self.class::COMMANDS[command]
44-
end
45-
46-
def launch_app(id)
47-
execute :launch_app, {}, {id: id}
48-
end
49-
50-
def cast_sinks
51-
execute :get_cast_sinks
52-
end
53-
54-
def cast_sink_to_use=(name)
55-
execute :set_cast_sink_to_use, {}, {sinkName: name}
56-
end
57-
58-
def cast_issue_message
59-
execute :cast_issue_message
60-
end
61-
62-
def start_cast_tab_mirroring(name)
63-
execute :start_cast_tab_mirroring, {}, {sinkName: name}
64-
end
65-
66-
def start_cast_desktop_mirroring(name)
67-
execute :start_cast_desktop_mirroring, {}, {sinkName: name}
68-
end
69-
70-
def stop_casting(name)
71-
execute :stop_casting, {}, {sinkName: name}
72-
end
73-
74-
def set_permission(name, value)
75-
execute :set_permission, {}, {descriptor: {name: name}, state: value}
76-
end
77-
78-
def network_conditions
79-
execute :get_network_conditions
80-
end
81-
82-
def network_conditions=(conditions)
83-
execute :set_network_conditions, {}, {network_conditions: conditions}
84-
end
85-
86-
def delete_network_conditions
87-
execute :delete_network_conditions
88-
end
89-
90-
def send_command(command_params)
91-
execute :send_command, {}, command_params
92-
end
93-
94-
def available_log_types
95-
types = execute :get_available_log_types
96-
Array(types).map(&:to_sym)
97-
end
98-
99-
def log(type)
100-
data = execute :get_log, {}, {type: type.to_s}
101-
102-
Array(data).map do |l|
103-
LogEntry.new l.fetch('level', 'UNKNOWN'), l.fetch('timestamp'), l.fetch('message')
104-
rescue KeyError
105-
next
106-
end
40+
CHROME_COMMANDS[command] || CHROMIUM_COMMANDS[command] || self.class::COMMANDS[command]
10741
end
10842
end # Bridge
10943
end # Chrome

0 commit comments

Comments
 (0)