Skip to content

Commit db643da

Browse files
committed
Implement RBS trace
1 parent c9cb77c commit db643da

39 files changed

+201
-1
lines changed

rb/Gemfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,5 @@ gem 'activesupport', '~> 7.0', require: false, platforms: %i[mri mingw x64_mingw
1010
gem 'curb', '~> 1.0.5', require: false, platforms: %i[mri mingw x64_mingw]
1111
gem 'debug', '~> 1.7', require: false, platforms: %i[mri mingw x64_mingw]
1212
gem 'steep', '~> 1.5.0', require: false, platforms: %i[mri mingw x64_mingw]
13+
14+
gem "rbs-trace", "~> 0.5.1"

rb/Gemfile.lock

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,9 @@ GEM
100100
ffi (~> 1.0)
101101
rbs (3.9.2)
102102
logger
103+
rbs-trace (0.5.1)
104+
prism (>= 0.3.0)
105+
rbs (>= 3.5.0)
103106
rchardet (1.9.0)
104107
rdoc (6.13.1)
105108
psych (>= 4.0.0)
@@ -199,6 +202,7 @@ DEPENDENCIES
199202
git (~> 1.19)
200203
rack (~> 2.0)
201204
rake (~> 13.0)
205+
rbs-trace (~> 0.5.1)
202206
rspec (~> 3.0)
203207
rubocop (~> 1.75)
204208
rubocop-performance (~> 1.25)

rb/lib/selenium/webdriver.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ def self.for(*args)
9595
# @return [Logger]
9696
#
9797

98+
# @rbs (**nil) -> Selenium::WebDriver::Logger
9899
def self.logger(**opts)
99100
level = $DEBUG || ENV.key?('DEBUG') ? :debug : :info
100101
@logger ||= WebDriver::Logger.new('Selenium', default_level: level, **opts)

rb/lib/selenium/webdriver/chrome.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ def self.path=(path)
3131
@path = path
3232
end
3333

34+
# @rbs () -> nil
3435
def self.path
3536
@path ||= nil
3637
end

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,13 @@ module Chrome
3030
class Driver < Chromium::Driver
3131
include LocalDriver
3232

33+
# @rbs (?options: Selenium::WebDriver::Chrome::Options, ?service: Selenium::WebDriver::Chrome::Service, ?url: nil, **nil) -> void
3334
def initialize(options: nil, service: nil, url: nil, **opts)
3435
caps, url = initialize_local_driver(options, service, url)
3536
super(caps: caps, url: url, **opts)
3637
end
3738

39+
# @rbs () -> Symbol
3840
def browser
3941
:chrome
4042
end

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,12 @@ module Features
3535
send_command: [:post, 'session/:session_id/goog/cdp/execute']
3636
}.freeze
3737

38+
# @rbs () -> Hash[untyped, untyped]
3839
def command_list
3940
CHROME_COMMANDS.merge(CHROMIUM_COMMANDS).merge(self.class::COMMANDS)
4041
end
4142

43+
# @rbs (Symbol) -> Array[untyped]
4244
def commands(command)
4345
command_list[command]
4446
end

rb/lib/selenium/webdriver/chrome/options.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ def enable_logging(browser_options)
3232
browser_options['goog:loggingPrefs'] = @logging_prefs
3333
end
3434

35+
# @rbs () -> nil
3536
def binary_path
3637
Chrome.path
3738
end

rb/lib/selenium/webdriver/chrome/service.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ class Service < WebDriver::Service
2626
SHUTDOWN_SUPPORTED = true
2727
DRIVER_PATH_ENV_KEY = 'SE_CHROMEDRIVER'
2828

29+
# @rbs () -> nil
2930
def log
3031
return @log unless @log.is_a? String
3132

rb/lib/selenium/webdriver/chromium/features.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ def delete_network_conditions
7575
execute :delete_network_conditions
7676
end
7777

78+
# @rbs (Hash[untyped, untyped]) -> Hash[untyped, untyped]
7879
def send_command(command_params)
7980
execute :send_command, {}, command_params
8081
end

rb/lib/selenium/webdriver/chromium/options.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ class Options < WebDriver::Options
6767
# @option opts [Array<String>] window_types A list of window types to appear in the list of window handles
6868
#
6969

70+
# @rbs (?profile: nil, **Array[untyped] | Hash[untyped, untyped] | nil) -> void
7071
def initialize(profile: nil, **opts)
7172
super(**opts)
7273

@@ -203,6 +204,7 @@ def enable_android(package: 'com.android.chrome', serial_number: nil, use_runnin
203204

204205
protected
205206

207+
# @rbs (Hash[untyped, untyped]) -> void
206208
def process_browser_options(browser_options)
207209
enable_logging(browser_options) unless @logging_prefs.empty?
208210

@@ -234,6 +236,7 @@ def validate_extension(path)
234236
@extensions << path
235237
end
236238

239+
# @rbs (Symbol | String) -> bool
237240
def camelize?(key)
238241
!%w[localState prefs].include?(key)
239242
end

rb/lib/selenium/webdriver/common/child_process.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,21 +34,25 @@ class ChildProcess
3434
attr_accessor :detach
3535
attr_writer :io
3636

37+
# @rbs (*String) -> Selenium::WebDriver::ChildProcess
3738
def self.build(*command)
3839
new(*command)
3940
end
4041

42+
# @rbs (*String) -> void
4143
def initialize(*command)
4244
@command = command
4345
@detach = false
4446
@pid = nil
4547
@status = nil
4648
end
4749

50+
# @rbs () -> String
4851
def io
4952
@io ||= Platform.null_device
5053
end
5154

55+
# @rbs () -> nil
5256
def start
5357
options = {%i[out err] => io}
5458
options[:pgroup] = true unless Platform.windows? # NOTE: this is a bug only in Windows 7
@@ -74,6 +78,7 @@ def alive?
7478
@pid && !exited?
7579
end
7680

81+
# @rbs () -> bool
7782
def exited?
7883
return false unless @pid
7984

@@ -90,6 +95,7 @@ def exited?
9095
true
9196
end
9297

98+
# @rbs (Integer) -> nil
9399
def poll_for_exit(timeout)
94100
WebDriver.logger.debug("Polling #{timeout} seconds for exit of #{@pid}", id: :process)
95101

@@ -128,6 +134,7 @@ def kill(pid)
128134
Process.kill(SIGKILL, pid)
129135
end
130136

137+
# @rbs (Integer, ?Integer) -> Array[untyped]?
131138
def waitpid2(pid, flags = 0)
132139
Process.waitpid2(pid, flags)
133140
end

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ class << self
4141
# @return [Driver]
4242
#
4343

44+
# @rbs (Symbol, ?Hash[untyped, untyped]) -> Selenium::WebDriver::Chrome::Driver
4445
def for(browser, opts = {})
4546
case browser
4647
when :chrome, :chrome_headless_shell
@@ -68,6 +69,7 @@ def for(browser, opts = {})
6869
# @api private
6970
#
7071

72+
# @rbs (?bridge: nil, ?listener: nil, **Hash[untyped, untyped] | URI::HTTP) -> void
7173
def initialize(bridge: nil, listener: nil, **opts)
7274
@devtools = nil
7375
bridge ||= create_bridge(**opts)
@@ -95,6 +97,7 @@ def status
9597
# @see Navigation
9698
#
9799

100+
# @rbs () -> Selenium::WebDriver::Navigation
98101
def navigate
99102
@navigate ||= WebDriver::Navigation.new(bridge)
100103
end
@@ -177,6 +180,7 @@ def page_source
177180
# Quit the browser
178181
#
179182

183+
# @rbs () -> nil
180184
def quit
181185
bridge.quit
182186
ensure
@@ -225,6 +229,7 @@ def window_handle
225229
# The value returned from the script.
226230
#
227231

232+
# @rbs (String, *nil) -> String
228233
def execute_script(script, *args)
229234
bridge.execute_script(script, *args)
230235
end
@@ -319,13 +324,15 @@ def ref
319324

320325
attr_reader :bridge
321326

327+
# @rbs (caps: Hash[untyped, untyped], url: URI::HTTP, ?http_client: nil) -> Selenium::WebDriver::Remote::Bridge
322328
def create_bridge(caps:, url:, http_client: nil)
323329
klass = caps['webSocketUrl'] ? Remote::BiDiBridge : Remote::Bridge
324330
klass.new(http_client: http_client, url: url).tap do |bridge|
325331
bridge.create_session(caps)
326332
end
327333
end
328334

335+
# @rbs (Selenium::WebDriver::Chrome::Service) -> URI::HTTP
329336
def service_url(service)
330337
@service_manager = service.launch
331338
@service_manager.uri
@@ -335,6 +342,7 @@ def screenshot
335342
bridge.screenshot
336343
end
337344

345+
# @rbs (Symbol) -> Array[untyped]
338346
def add_extensions(browser)
339347
extensions = case browser
340348
when :chrome, :chrome_headless_shell, :msedge, :microsoftedge

rb/lib/selenium/webdriver/common/driver_extensions/has_cdp.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ module HasCDP
2727
# @return [Hash]
2828
#
2929

30+
# @rbs (String, **String) -> Hash[untyped, untyped]
3031
def execute_cdp(cmd, **params)
3132
@bridge.send_command(cmd: cmd, params: params)
3233
end

rb/lib/selenium/webdriver/common/driver_finder.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,25 +26,30 @@ def self.path(options, service_class)
2626
new(options, service_class.new).driver_path
2727
end
2828

29+
# @rbs (Selenium::WebDriver::Chrome::Options, Selenium::WebDriver::Chrome::Service) -> void
2930
def initialize(options, service)
3031
@options = options
3132
@service = service
3233
end
3334

35+
# @rbs () -> String
3436
def browser_path
3537
paths[:browser_path]
3638
end
3739

40+
# @rbs () -> String
3841
def driver_path
3942
paths[:driver_path]
4043
end
4144

45+
# @rbs () -> bool
4246
def browser_path?
4347
!browser_path.nil? && !browser_path.empty?
4448
end
4549

4650
private
4751

52+
# @rbs () -> Hash[untyped, untyped]
4853
def paths
4954
@paths ||= begin
5055
path = @service.class.driver_path
@@ -76,6 +81,7 @@ def paths
7681
end
7782
end
7883

84+
# @rbs () -> Array[untyped]
7985
def to_args
8086
args = ['--browser', @options.browser_name]
8187
if @options.browser_version

rb/lib/selenium/webdriver/common/error.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ module Error
2525
# @param [String, nil] error
2626
#
2727

28+
# @rbs (nil) -> nil
2829
def self.for_error(error)
2930
return if error.nil?
3031

rb/lib/selenium/webdriver/common/local_driver.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
module Selenium
2121
module WebDriver
2222
module LocalDriver
23+
# @rbs (Selenium::WebDriver::Chrome::Options, Selenium::WebDriver::Chrome::Service, nil) -> Array[untyped]
2324
def initialize_local_driver(options, service, url)
2425
raise ArgumentError, "Can't initialize #{self.class} with :url" if url
2526

@@ -30,6 +31,7 @@ def initialize_local_driver(options, service, url)
3031
[caps, url]
3132
end
3233

34+
# @rbs (Selenium::WebDriver::Chrome::Options, Selenium::WebDriver::Chrome::Service) -> Hash[untyped, untyped]
3335
def process_options(options, service)
3436
default_options = Options.send(browser)
3537
options ||= default_options

rb/lib/selenium/webdriver/common/logger.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ def allow(*ids)
115115
# @param [Symbol, Array<Symbol>] id
116116
# @yield see #deprecate
117117
#
118+
# @rbs (String, ?id: Array[untyped] | Symbol) -> nil
118119
def debug(message, id: [], &block)
119120
discard_or_log(:debug, message, id, &block)
120121
end
@@ -191,6 +192,7 @@ def create_logger(name, level:)
191192
logger
192193
end
193194

195+
# @rbs (Symbol, String, Array[untyped] | Symbol) -> nil
194196
def discard_or_log(level, message, id)
195197
id = Array(id)
196198
return if @ignored.intersect?(id)

rb/lib/selenium/webdriver/common/navigation.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
module Selenium
2121
module WebDriver
2222
class Navigation
23+
# @rbs (Selenium::WebDriver::Remote::Bridge) -> void
2324
def initialize(bridge)
2425
@bridge = bridge
2526
end
@@ -28,6 +29,7 @@ def initialize(bridge)
2829
# Navigate to the given URL
2930
#
3031

32+
# @rbs (String) -> void
3133
def to(url)
3234
@bridge.get url
3335
end

0 commit comments

Comments
 (0)