Skip to content

Commit 289760c

Browse files
committed
Add RBS comments
1 parent db643da commit 289760c

File tree

154 files changed

+929
-1268
lines changed

Some content is hidden

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

154 files changed

+929
-1268
lines changed

rb/lib/selenium/devtools.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ module DevTools
2222
class << self
2323
attr_accessor :version
2424

25+
# @rbs () -> void
2526
def load_version
2627
require "selenium/devtools/v#{@version}"
2728
rescue LoadError

rb/lib/selenium/server.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,7 @@ def stop
215215
@log_file&.close
216216
end
217217

218+
# @rbs () -> String
218219
def webdriver_url
219220
"http://#{@host}:#{@port}/wd/hub"
220221
end

rb/lib/selenium/webdriver/atoms.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,20 @@
2020
module Selenium
2121
module WebDriver
2222
module Atoms
23+
# @rbs (Symbol) -> String
2324
def atom_script(function_name)
2425
format("/* #{function_name} */return (%<atom>s).apply(null, arguments)",
2526
atom: read_atom(function_name))
2627
end
2728

2829
private
2930

31+
# @rbs (Symbol) -> String
3032
def read_atom(function)
3133
File.read(File.expand_path("../atoms/#{function}.js", __FILE__))
3234
end
3335

36+
# @rbs (Symbol, *Selenium::WebDriver::Element | String | Hash[untyped, untyped]) -> (String | Array[untyped])
3437
def execute_atom(function_name, *arguments)
3538
execute_script(atom_script(function_name), *arguments)
3639
end

rb/lib/selenium/webdriver/bidi.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,30 +31,37 @@ class BiDi
3131
autoload :InterceptedAuth, 'selenium/webdriver/bidi/network/intercepted_auth'
3232
autoload :InterceptedItem, 'selenium/webdriver/bidi/network/intercepted_item'
3333

34+
# @rbs (url: String) -> void
3435
def initialize(url:)
3536
@ws = WebSocketConnection.new(url: url)
3637
end
3738

39+
# @rbs () -> nil
3840
def close
3941
@ws.close
4042
end
4143

44+
# @rbs () -> Hash[untyped, untyped]
4245
def callbacks
4346
@ws.callbacks
4447
end
4548

49+
# @rbs (String) -> void
4650
def add_callback(event, &block)
4751
@ws.add_callback(event, &block)
4852
end
4953

54+
# @rbs (String, Integer) -> void
5055
def remove_callback(event, id)
5156
@ws.remove_callback(event, id)
5257
end
5358

59+
# @rbs () -> Selenium::WebDriver::BiDi::Session
5460
def session
5561
@session ||= Session.new(self)
5662
end
5763

64+
# @rbs (String, **String | String | Integer | String | bool) -> Hash[untyped, untyped]
5865
def send_cmd(method, **params)
5966
data = {method: method, params: params.compact}
6067
message = @ws.send_cmd(**data)
@@ -63,6 +70,7 @@ def send_cmd(method, **params)
6370
message['result']
6471
end
6572

73+
# @rbs (Hash[untyped, untyped]) -> String
6674
def error_message(message)
6775
"#{message['error']}: #{message['message']}\n#{message['stacktrace']}"
6876
end

rb/lib/selenium/webdriver/bidi/browsing_context.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ class BrowsingContext
3232
}.freeze
3333

3434
# TODO: store current window handle in bridge object instead of always calling it
35+
# @rbs (Selenium::WebDriver::Remote::BiDiBridge) -> void
3536
def initialize(bridge)
3637
@bridge = bridge
3738
@bidi = @bridge.bidi
@@ -44,6 +45,7 @@ def initialize(bridge)
4445
# @param url [String] The URL to navigate to.
4546
# @param context_id [String, NilClass] The ID of the browsing context to navigate in.
4647
# Defaults to the window handle of the current context.
48+
# @rbs (String, ?context_id: nil) -> Hash[untyped, untyped]
4749
def navigate(url, context_id: nil)
4850
context_id ||= @bridge.window_handle
4951
@bidi.send_cmd('browsingContext.navigate', context: context_id, url: url, wait: @readiness)
@@ -55,6 +57,7 @@ def navigate(url, context_id: nil)
5557
# Positive values go forwards, negative values go backwards.
5658
# @param context_id [String, NilClass] The ID of the context to traverse.
5759
# Defaults to the window handle of the current context.
60+
# @rbs (Integer, ?context_id: nil) -> Hash[untyped, untyped]
5861
def traverse_history(delta, context_id: nil)
5962
context_id ||= @bridge.window_handle
6063
@bidi.send_cmd('browsingContext.traverseHistory', context: context_id, delta: delta)
@@ -65,6 +68,7 @@ def traverse_history(delta, context_id: nil)
6568
# Defaults to the window handle of the current context.
6669
# @param [Boolean] ignore_cache Whether to bypass the cache when reloading.
6770
# Defaults to false.
71+
# @rbs (?context_id: nil, ?ignore_cache: bool) -> Hash[untyped, untyped]
6872
def reload(context_id: nil, ignore_cache: false)
6973
context_id ||= @bridge.window_handle
7074
params = {context: context_id, ignore_cache: ignore_cache, wait: @readiness}
@@ -75,6 +79,7 @@ def reload(context_id: nil, ignore_cache: false)
7579
#
7680
# @param [String] context_id The ID of the context to close.
7781
# Defaults to the window handle of the current context.
82+
# @rbs (?context_id: String) -> void
7883
def close(context_id: nil)
7984
context_id ||= @bridge.window_handle
8085
@bidi.send_cmd('browsingContext.close', context: context_id)
@@ -88,23 +93,27 @@ def close(context_id: nil)
8893
# Defaults to the current window handle.
8994
#
9095
# @return [String] The context ID of the created browsing context.
96+
# @rbs (?type: nil, ?context_id: nil) -> String
9197
def create(type: nil, context_id: nil)
9298
type ||= :window
9399
context_id ||= @bridge.window_handle
94100
result = @bidi.send_cmd('browsingContext.create', type: type.to_s, referenceContext: context_id)
95101
result['context']
96102
end
97103

104+
# @rbs (?context_id: nil, ?width: Integer, ?height: Integer, ?device_pixel_ratio: Float) -> void
98105
def set_viewport(context_id: nil, width: nil, height: nil, device_pixel_ratio: nil)
99106
context_id ||= @bridge.window_handle
100107
params = {context: context_id, viewport: {width:, height:}, device_pixel_ratio:}
101108
@bidi.send_cmd('browsingContext.setViewport', **params)
102109
end
103110

111+
# @rbs (String, ?accept: bool, ?text: nil | String) -> void
104112
def handle_user_prompt(context_id, accept: true, text: nil)
105113
@bidi.send_cmd('browsingContext.handleUserPrompt', context: context_id, accept: accept, text: text)
106114
end
107115

116+
# @rbs (?context_id: nil) -> void
108117
def activate(context_id: nil)
109118
context_id ||= @bridge.window_handle
110119
@bidi.send_cmd('browsingContext.activate', context: context_id)

rb/lib/selenium/webdriver/bidi/log_handler.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,15 @@ class LogHandler
2424
ConsoleLogEntry = BiDi::Struct.new(:level, :text, :timestamp, :stack_trace, :type, :source, :method, :args)
2525
JavaScriptLogEntry = BiDi::Struct.new(:level, :text, :timestamp, :stack_trace, :type, :source)
2626

27+
# @rbs (Selenium::WebDriver::BiDi) -> void
2728
def initialize(bidi)
2829
@bidi = bidi
2930
@log_entry_subscribed = false
3031
end
3132

3233
# @return [int] id of the handler
3334
# steep:ignore:start
35+
# @rbs (String) -> Integer
3436
def add_message_handler(type)
3537
subscribe_log_entry unless @log_entry_subscribed
3638
@bidi.add_callback('log.entryAdded') do |params|
@@ -43,13 +45,15 @@ def add_message_handler(type)
4345
# steep:ignore:end
4446

4547
# @param [int] id of the handler previously added
48+
# @rbs (Integer) -> nil
4649
def remove_message_handler(id)
4750
@bidi.remove_callback('log.entryAdded', id)
4851
unsubscribe_log_entry if @log_entry_subscribed && @bidi.callbacks['log.entryAdded'].empty?
4952
end
5053

5154
private
5255

56+
# @rbs () -> bool
5357
def subscribe_log_entry
5458
@bidi.session.subscribe('log.entryAdded')
5559
@log_entry_subscribed = true

rb/lib/selenium/webdriver/bidi/log_inspector.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ class LogInspector
4040
WARNING: 'warning'
4141
}.freeze
4242

43+
# @rbs (Selenium::WebDriver::Chrome::Driver, ?nil) -> void
4344
def initialize(driver, browsing_context_ids = nil)
4445
WebDriver.logger.deprecate('LogInspector class',
4546
'Script class with driver.script',
@@ -54,6 +55,7 @@ def initialize(driver, browsing_context_ids = nil)
5455
@bidi.session.subscribe('log.entryAdded', browsing_context_ids)
5556
end
5657

58+
# @rbs (?Selenium::WebDriver::BiDi::FilterBy?) -> void
5759
def on_console_entry(filter_by = nil, &block)
5860
check_valid_filter(filter_by)
5961

@@ -63,6 +65,7 @@ def on_console_entry(filter_by = nil, &block)
6365
end
6466
end
6567

68+
# @rbs (?Selenium::WebDriver::BiDi::FilterBy?) -> void
6669
def on_javascript_log(filter_by = nil, &block)
6770
check_valid_filter(filter_by)
6871

@@ -72,13 +75,15 @@ def on_javascript_log(filter_by = nil, &block)
7275
end
7376
end
7477

78+
# @rbs () -> void
7579
def on_javascript_exception(&block)
7680
on_log do |params|
7781
type = params['type']
7882
javascript_log_events(params, FilterBy.log_level('error'), &block) if type.eql?('javascript')
7983
end
8084
end
8185

86+
# @rbs (?Selenium::WebDriver::BiDi::FilterBy?) -> Integer?
8287
def on_log(filter_by = nil, &block)
8388
unless filter_by.nil?
8489
check_valid_filter(filter_by)
@@ -94,17 +99,20 @@ def on_log(filter_by = nil, &block)
9499

95100
private
96101

102+
# @rbs (Symbol) -> Integer
97103
def on(event, &block)
98104
event = EVENTS[event] if event.is_a?(Symbol)
99105
@bidi.add_callback("log.#{event}", &block)
100106
end
101107

108+
# @rbs (Selenium::WebDriver::BiDi::FilterBy?) -> void
102109
def check_valid_filter(filter_by)
103110
return if filter_by.nil? || filter_by.instance_of?(FilterBy)
104111

105112
raise "Pass valid FilterBy object. Received: #{filter_by.inspect}"
106113
end
107114

115+
# @rbs (Hash[untyped, untyped], Selenium::WebDriver::BiDi::FilterBy?) -> Array[untyped]?
108116
def console_log_events(params, filter_by)
109117
event = ConsoleLogEntry.new(
110118
level: params['level'],
@@ -125,6 +133,7 @@ def console_log_events(params, filter_by)
125133
yield(event)
126134
end
127135

136+
# @rbs (Hash[untyped, untyped], Selenium::WebDriver::BiDi::FilterBy?) -> Selenium::WebDriver::BiDi::JavascriptLogEntry?
128137
def javascript_log_events(params, filter_by)
129138
event = JavascriptLogEntry.new(
130139
level: params['level'],

rb/lib/selenium/webdriver/bidi/network.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,12 @@ class Network
3636
auth_required: 'authRequired'
3737
}.freeze
3838

39+
# @rbs (Selenium::WebDriver::BiDi) -> void
3940
def initialize(bidi)
4041
@bidi = bidi
4142
end
4243

44+
# @rbs (?phases: Array[untyped], ?contexts: nil, ?url_patterns: Array[untyped], ?pattern_type: nil | Symbol) -> Hash[untyped, untyped]
4345
def add_intercept(phases: [], contexts: nil, url_patterns: nil, pattern_type: :string)
4446
url_patterns = url_patterns && pattern_type ? UrlPattern.format_pattern(url_patterns, pattern_type) : nil
4547
@bidi.send_cmd('network.addIntercept',
@@ -48,10 +50,12 @@ def add_intercept(phases: [], contexts: nil, url_patterns: nil, pattern_type: :s
4850
urlPatterns: url_patterns)
4951
end
5052

53+
# @rbs (String) -> void
5154
def remove_intercept(intercept)
5255
@bidi.send_cmd('network.removeIntercept', intercept: intercept)
5356
end
5457

58+
# @rbs (String, String, String) -> Hash[untyped, untyped]
5559
def continue_with_auth(request_id, username, password)
5660
@bidi.send_cmd(
5761
'network.continueWithAuth',
@@ -65,6 +69,7 @@ def continue_with_auth(request_id, username, password)
6569
)
6670
end
6771

72+
# @rbs (String) -> Hash[untyped, untyped]
6873
def continue_without_auth(request_id)
6974
@bidi.send_cmd(
7075
'network.continueWithAuth',
@@ -73,6 +78,7 @@ def continue_without_auth(request_id)
7378
)
7479
end
7580

81+
# @rbs (String) -> Hash[untyped, untyped]
7682
def cancel_auth(request_id)
7783
@bidi.send_cmd(
7884
'network.continueWithAuth',
@@ -81,6 +87,7 @@ def cancel_auth(request_id)
8187
)
8288
end
8389

90+
# @rbs (**(String | Array[untyped])? | String | Hash[untyped, untyped] | Array[untyped]) -> Hash[untyped, untyped]?
8491
def continue_request(**args)
8592
@bidi.send_cmd(
8693
'network.continueRequest',
@@ -93,13 +100,15 @@ def continue_request(**args)
93100
)
94101
end
95102

103+
# @rbs (String) -> Hash[untyped, untyped]?
96104
def fail_request(request_id)
97105
@bidi.send_cmd(
98106
'network.failRequest',
99107
request: request_id
100108
)
101109
end
102110

111+
# @rbs (**(String | Array[untyped])? | (String | Array[untyped] | Hash[untyped, untyped])?) -> Hash[untyped, untyped]?
103112
def continue_response(**args)
104113
@bidi.send_cmd(
105114
'network.continueResponse',
@@ -112,6 +121,7 @@ def continue_response(**args)
112121
)
113122
end
114123

124+
# @rbs (**(String | Array[untyped] | Hash[untyped, untyped] | Integer)?) -> Hash[untyped, untyped]
115125
def provide_response(**args)
116126
@bidi.send_cmd(
117127
'network.provideResponse',
@@ -124,10 +134,12 @@ def provide_response(**args)
124134
)
125135
end
126136

137+
# @rbs (String, *String) -> Hash[untyped, untyped]
127138
def set_cache_behavior(behavior, *contexts)
128139
@bidi.send_cmd('network.setCacheBehavior', cacheBehavior: behavior, contexts: contexts)
129140
end
130141

142+
# @rbs (Symbol) -> Hash[untyped, untyped]
131143
def on(event, &block)
132144
event = EVENTS[event] if event.is_a?(Symbol)
133145
@bidi.add_callback(event, &block)

rb/lib/selenium/webdriver/bidi/network/intercepted_auth.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,17 @@ module Selenium
2121
module WebDriver
2222
class BiDi
2323
class InterceptedAuth < InterceptedItem
24+
# @rbs (String, String) -> Hash[untyped, untyped]
2425
def authenticate(username, password)
2526
network.continue_with_auth(id, username, password)
2627
end
2728

29+
# @rbs () -> Hash[untyped, untyped]
2830
def skip
2931
network.continue_without_auth(id)
3032
end
3133

34+
# @rbs () -> Hash[untyped, untyped]
3235
def cancel
3336
network.cancel_auth(id)
3437
end

rb/lib/selenium/webdriver/bidi/network/intercepted_item.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,13 @@ class BiDi
2323
class InterceptedItem
2424
attr_reader :network, :request
2525

26+
# @rbs (Selenium::WebDriver::BiDi::Network, Hash[untyped, untyped]) -> void
2627
def initialize(network, request)
2728
@network = network
2829
@request = request
2930
end
3031

32+
# @rbs () -> String
3133
def id
3234
@id ||= @request['request']
3335
end

0 commit comments

Comments
 (0)