Skip to content

Commit 5b7c95b

Browse files
authored
[rb] Add full RBS support (#13234)
1 parent f54b068 commit 5b7c95b

File tree

182 files changed

+3603
-90
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

182 files changed

+3603
-90
lines changed

rb/Steepfile

Lines changed: 82 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,88 @@
11
# frozen_string_literal: true
22

3+
# rubocop:disable Metrics/BlockLength -- Disable due to the steep configuration not matching rubocop expectations
34
target :lib do
4-
signature 'sig' # Signature directory
5+
signature 'sig', '.gem_rbs_collection/rubyzip' # Signature directory
56
check 'lib' # Directory name
7+
# Total amount of errors ignore 66 in 31 files
8+
ignore(
9+
# Ignore line 166 due to UDP RBS issue
10+
'lib/selenium/webdriver/common/platform.rb',
11+
# Ignore due to webmock gem not having RBS signatures
12+
'lib/selenium/webdriver/remote/http/curb.rb',
13+
# Ignore due to line 71, there is one last error where RBS thinks backtrace is nil
14+
'lib/selenium/webdriver/remote/response.rb',
15+
# Ignore due to Errno::EACCES error
16+
'lib/selenium/webdriver/support/color.rb',
17+
'lib/selenium/webdriver/common/port_prober.rb',
18+
# Ignore due to error overloading
19+
'lib/selenium/webdriver/common/socket_poller.rb',
20+
# Ignore due to Parser on line 611
21+
'lib/selenium/webdriver/remote/bridge.rb',
22+
# Ignore due to error on line 101 with block
23+
'lib/selenium/webdriver/devtools/network_interceptor.rb',
24+
# Ignore due to error on line 21 with overloading issues
25+
'lib/selenium/webdriver/common/virtual_authenticator/credential.rb',
26+
# Ignore due to error with the Zipper RBS
27+
'lib/selenium/webdriver/common/zipper.rb',
28+
# Ignore due to error on line 117 with the debug? method
29+
'lib/selenium/webdriver/common/selenium_manager.rb',
30+
# Ignore due to line 230 with the overloading issues
31+
'lib/selenium/webdriver/common/action_builder.rb',
32+
# Ignore due to CAPABILITIES not able to be found on line 55
33+
'lib/selenium/webdriver/common/options.rb',
34+
# Ignore due to strftime error in RBS on line 188
35+
'lib/selenium/webdriver/common/logger.rb',
36+
# Ignore due to error with Process
37+
'lib/selenium/webdriver/common/child_process.rb',
38+
# Ignore due to Net::HTTP not being found on line 49
39+
'lib/selenium/webdriver/chromium/driver.rb',
40+
# Ignore due to error on line 37 with include?
41+
'lib/selenium/webdriver/support/guards/guard_condition.rb',
42+
# Ignore due to positional argument error on line 69
43+
'lib/selenium/webdriver/common/socket_lock.rb',
44+
# Ignore due to is_a? bot error on line 70
45+
'lib/selenium/webdriver/remote/driver.rb',
46+
# Ignore due to line 118 causing an error with URI & Net::HTTP
47+
'lib/selenium/server.rb',
48+
# Ignore due to overloading issue on line 84
49+
'lib/selenium/webdriver/chromium/features.rb',
50+
# Ignore due to line 59 with the same URI & Net::HTTP issue
51+
'lib/selenium/webdriver/firefox/driver.rb',
52+
# Ignore due to line 27 with overloading issue
53+
'lib/selenium/webdriver/bidi/log/console_log_entry.rb',
54+
# Ignore due to line 89 with overloading issue
55+
'lib/selenium/webdriver.rb',
56+
# Ignore due to line 37 with overloading issue
57+
'lib/selenium/webdriver/common/interactions/wheel_input.rb',
58+
# Cannot override last error on line 71
59+
'lib/selenium/webdriver/common/wait.rb',
60+
# Cannot override params on line 83
61+
'lib/selenium/webdriver/bidi/log_inspector.rb',
62+
# Kwargs issue on line 74
63+
'lib/selenium/webdriver/common/driver.rb',
64+
# issue with the Zipper RBS library on line 54
65+
'lib/selenium/webdriver/firefox/extension.rb',
66+
# Ignored due to return of last match in line 57 and 59
67+
'lib/selenium/webdriver/firefox/profiles_ini.rb',
68+
# Ignored due to error on line 100 of response being nillable
69+
'lib/selenium/webdriver/remote/http/default.rb'
70+
)
671

7-
library 'forwardable' # Standard libraries
72+
# Standard libraries used in the project
73+
library(
74+
'base64',
75+
'date',
76+
'erb',
77+
'find',
78+
'forwardable',
79+
'ipaddr',
80+
'net-http',
81+
'openssl',
82+
'tmpdir',
83+
'securerandom',
84+
'uri',
85+
'zlib'
86+
)
887
end
88+
# rubocop:enable Metrics/BlockLength

rb/lib/selenium/devtools/support/cdp_client_generator.rb

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,9 @@ module DevTools
2626
module Support
2727
class CDPClientGenerator
2828
# Input JSON files are generated from PDL tasks.
29-
DOMAIN_TEMPLATE_PATH = File.expand_path('cdp/domain.rb.erb', __dir__)
30-
LOADER_TEMPLATE_PATH = File.expand_path('cdp/loader.rb.erb', __dir__)
29+
DIR = __dir__ || ''
30+
DOMAIN_TEMPLATE_PATH = File.expand_path('cdp/domain.rb.erb', DIR)
31+
LOADER_TEMPLATE_PATH = File.expand_path('cdp/loader.rb.erb', DIR)
3132

3233
RESERVED_KEYWORDS = %w[end].freeze
3334

@@ -39,9 +40,9 @@ def call(output_dir:, version:, **opts)
3940
@version = version
4041

4142
browser_protocol_path = opts.delete(:browser_protocol_path) do
42-
File.expand_path('cdp/browser_protocol.json', __dir__)
43+
File.expand_path('cdp/browser_protocol.json', DIR)
4344
end
44-
js_protocol_path = opts.delete(:js_protocol_path) { File.expand_path('cdp/js_protocol.json', __dir__) }
45+
js_protocol_path = opts.delete(:js_protocol_path) { File.expand_path('cdp/js_protocol.json', DIR) }
4546

4647
raise ArgumentError, "Invalid arguments: #{opts.keys}" unless opts.empty?
4748

@@ -103,7 +104,7 @@ def process_loader(domains)
103104
Selenium::DevTools::Support::CDPClientGenerator.new.call(
104105
browser_protocol_path: browser_protocol_path,
105106
js_protocol_path: js_protocol_path,
106-
output_dir: loader_path.sub(/\.rb$/, ''),
107+
output_dir: loader_path&.sub(/\.rb$/, ''),
107108
loader_path: loader_path,
108109
version: version
109110
)

rb/lib/selenium/webdriver.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ module WebDriver
4949
# @api private
5050

5151
def self.root
52-
@root ||= File.expand_path('..', __dir__)
52+
@root ||= File.expand_path('..', __dir__.to_s)
5353
end
5454

5555
#

rb/lib/selenium/webdriver/common/driver.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ def [](sel)
292292
end
293293

294294
def browser
295-
bridge&.browser
295+
bridge.browser
296296
end
297297

298298
def capabilities

rb/lib/selenium/webdriver/common/manager.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def add_cookie(opts = {})
5656
opts[:httpOnly] = http_only if http_only
5757

5858
obj = opts.delete(:expires)
59-
opts[:expiry] = seconds_from(obj).to_i if obj
59+
opts[:expiry] = seconds_from(obj).to_int if obj
6060

6161
@bridge.add_cookie opts
6262
end

rb/lib/selenium/webdriver/common/options.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ def convert_json_key(key, camelize: true)
177177
end
178178

179179
def camel_case(str)
180-
str.gsub(/_([a-z])/) { Regexp.last_match(1).upcase }
180+
str.gsub(/_([a-z])/) { Regexp.last_match(1)&.upcase }
181181
end
182182
end # Options
183183
end # WebDriver

rb/lib/selenium/webdriver/common/service.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ def initialize(path: nil, port: nil, log: nil, args: nil)
8888

8989
def launch
9090
@executable_path ||= begin
91-
default_options = WebDriver.const_get("#{self.class.name.split('::')[2]}::Options").new
91+
default_options = WebDriver.const_get("#{self.class.name&.split('::')&.[](2)}::Options").new
9292
DriverFinder.path(default_options, self.class)
9393
end
9494
ServiceManager.new(self).tap(&:start)

rb/lib/selenium/webdriver/common/socket_poller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ def listening?
7878
def listening?
7979
addr = Socket.getaddrinfo(@host, @port, Socket::AF_INET, Socket::SOCK_STREAM)
8080
sock = Socket.new(Socket::AF_INET, Socket::SOCK_STREAM, 0)
81-
sockaddr = Socket.pack_sockaddr_in(@port, addr[0][3])
81+
sockaddr = Socket.pack_sockaddr_in(@port, addr[0][3].to_s)
8282

8383
begin
8484
sock.connect_nonblock sockaddr

rb/lib/selenium/webdriver/firefox/profile.rb

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ class Profile
2424
include ProfileHelper
2525

2626
VALID_PREFERENCE_TYPES = [TrueClass, FalseClass, Integer, Float, String].freeze
27+
WEBDRIVER_PREFS = {
28+
port: 'webdriver_firefox_port',
29+
log_file: 'webdriver.log.file'
30+
}.freeze
2731

2832
DEFAULT_PREFERENCES = {
2933
'browser.newtabpage.enabled' => false,
@@ -35,8 +39,8 @@ class Profile
3539

3640
LOCK_FILES = %w[.parentlock parent.lock lock].freeze
3741

38-
attr_reader :name, :log_file
39-
attr_writer :secure_ssl, :load_no_focus_lib
42+
attr_reader :name, :log_file
43+
attr_writer :secure_ssl, :load_no_focus_lib
4044

4145
class << self
4246
def ini
@@ -206,8 +210,8 @@ def read_user_prefs(path)
206210
File.read(path).split("\n").each do |line|
207211
next unless line =~ /user_pref\("([^"]+)"\s*,\s*(.+?)\);/
208212

209-
key = Regexp.last_match(1).strip
210-
value = Regexp.last_match(2).strip
213+
key = Regexp.last_match(1)&.strip
214+
value = Regexp.last_match(2)&.strip
211215

212216
# wrap the value in an array to make it a valid JSON string.
213217
prefs[key] = JSON.parse("[#{value}]").first
@@ -223,7 +227,9 @@ def write_prefs(prefs, path)
223227
end
224228
end
225229
end
226-
end # Profile
230+
end
231+
232+
# Profile
227233
end # Firefox
228234
end # WebDriver
229235
end # Selenium

rb/lib/selenium/webdriver/firefox/profiles_ini.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def parse
5252
when /^\[Profile/
5353
name, path = nil if path_for(name, is_relative, path)
5454
when /^Name=(.+)$/
55-
name = Regexp.last_match(1).strip
55+
name = Regexp.last_match(1)&.strip
5656
when /^IsRelative=(.+)$/
5757
is_relative = Regexp.last_match(1).strip == '1'
5858
when /^Path=(.+)$/

0 commit comments

Comments
 (0)