Skip to content

Commit e044767

Browse files
authored
feat: add more rbs (#645)
* update rbs lock * fix rbs * add update * update rbs and a couple of rb * run steep as well
1 parent 0e44a0f commit e044767

Some content is hidden

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

49 files changed

+283
-108
lines changed

.github/workflows/unittest.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ jobs:
3030
- name: Run tests
3131
run: |
3232
bundle exec rake rubocop
33+
bundle exec rake steep
3334
bundle exec rake test:unit
3435
APPIUM_DRIVER=espresso bundle exec rake test:unit:android
3536
APPIUM_DRIVER=appium bundle exec rake test:unit

Gemfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ gem 'parallel_tests'
1010
gem 'rake', '~> 13.0'
1111
gem 'rubocop', '1.81.7'
1212
gem 'simplecov'
13-
gem 'steep', '~> 1.9.3'
13+
gem 'steep', '~> 1.10.0'
1414
gem 'webmock', '~> 3.26.0'
1515
gem 'yard', '~> 0.9.11'

Rakefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,5 +120,5 @@ end
120120

121121
desc('Run Steep type check')
122122
task :steep do
123-
system('steep check')
123+
system 'steep check --severity-level=error'
124124
end

lib/appium_lib_core.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ def self.symbolize_keys(hash, nested: false, enable_deprecation_msg: true)
6161

6262
module Core
6363
# @see Appium::Core::Driver.for
64-
def self.for(*args)
65-
Core::Driver.for(*args)
64+
def self.for(opts = {})
65+
Core::Driver.for(opts)
6666
end
6767
end
6868
end

lib/appium_lib_core/common/base/bidi_bridge.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ module Appium
1818
module Core
1919
class Base
2020
class BiDiBridge < ::Appium::Core::Base::Bridge
21+
# steep:ignore:start
22+
2123
attr_reader :bidi
2224

2325
# Override
@@ -85,6 +87,8 @@ def close
8587
execute(:close_window).tap { |handles| bidi.close if handles.empty? }
8688
end
8789

90+
# steep:ignore:end
91+
8892
private
8993

9094
def browsing_context

lib/appium_lib_core/common/base/bridge.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@ class Bridge < ::Selenium::WebDriver::Remote::Bridge
3737
include Device::ExecuteDriver
3838
include Device::Orientation
3939

40+
# steep:ignore:start
4041
Bridge.locator_converter = LocatorConverter.new
42+
# steep:ignore:end
4143

4244
# Prefix for extra capability defined by W3C
4345
APPIUM_PREFIX = 'appium:'
@@ -141,7 +143,7 @@ def add_appium_prefix(capabilities)
141143
private
142144

143145
def camel_case(str_or_sym)
144-
str_or_sym.to_s.gsub(/_([a-z])/) { Regexp.last_match(1).upcase }
146+
str_or_sym.to_s.gsub(/_([a-z])/) { Regexp.last_match(1)&.upcase }
145147
end
146148

147149
def extension_prefix?(capability_name)
@@ -204,12 +206,14 @@ def status
204206
# @driver.action.click(element).perform # The 'click' is a part of 'PointerActions'
205207
#
206208
def action(_deprecated_async = nil, async: false, devices: nil)
209+
# steep:ignore:start
207210
::Selenium::WebDriver::ActionBuilder.new(
208211
self,
209212
devices: devices || [::Selenium::WebDriver::Interactions.pointer(:touch, name: 'touch')],
210213
async: async,
211214
duration: 50 # milliseconds
212215
)
216+
# steep:ignore:end
213217
end
214218

215219
# Port from MJSONWP
@@ -278,7 +282,9 @@ def log(type)
278282
data = execute :get_log, {}, { type: type.to_s }
279283

280284
Array(data).map do |l|
285+
# steep:ignore:start
281286
::Selenium::WebDriver::LogEntry.new l.fetch('level', 'UNKNOWN'), l.fetch('timestamp'), l.fetch('message')
287+
# steep:ignore:end
282288
rescue KeyError
283289
next
284290
end

lib/appium_lib_core/common/base/driver.rb

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@ class Driver < ::Selenium::WebDriver::Driver
3636

3737
include ::Appium::Core::Waitable
3838

39+
# steep:ignore:start
3940
::Selenium::WebDriver::SearchContext.extra_finders = ::Appium::Core::Base::SearchContext::APPIUM_EXTRA_FINDERS
41+
# steep:ignore:end
4042

4143
# Private API.
4244
# Do not use this for general use. Used by flutter driver to get bridge for creating a new element
@@ -57,7 +59,9 @@ def initialize(bridge: nil, listener: nil, **opts) # rubocop:disable Lint/Missin
5759
# internal use
5860
@has_bidi = false
5961

62+
# steep:ignore:start
6063
::Selenium::WebDriver::Remote::Bridge.element_class = ::Appium::Core::Element
64+
# steep:ignore:end
6165
bridge ||= create_bridge(**opts)
6266
add_extensions(bridge.browser)
6367
@bridge = listener ? ::Appium::Support::EventFiringBridge.new(bridge, listener, **original_opts) : bridge
@@ -83,7 +87,9 @@ def create_bridge(**opts)
8387

8488
@has_bidi = capabilities && capabilities['webSocketUrl'] ? true : false
8589
bridge_clzz = @has_bidi ? ::Appium::Core::Base::BiDiBridge : ::Appium::Core::Base::Bridge
90+
# steep:ignore:start
8691
bridge = bridge_clzz.new(**bridge_opts)
92+
# steep:ignore:end
8793

8894
if session_id.nil?
8995
bridge.create_session(capabilities)
@@ -220,7 +226,9 @@ def add_command(method:, url:, name:, &block)
220226
def key_action(async: false)
221227
@bridge.action(
222228
async: async,
229+
# steep:ignore:start
223230
devices: [::Selenium::WebDriver::Interactions.key('keyboard')]
231+
# steep:ignore:end
224232
)
225233
end
226234

@@ -627,7 +635,7 @@ def background_app(duration = 0)
627635
#
628636
def install_app(path, **options)
629637
# TODO: use mobile command in the background?
630-
options = options.transform_keys { |key| key.to_s.gsub(/_./) { |v| v[1].upcase } } unless options.nil?
638+
options = options.transform_keys { |key| key.to_s.gsub(/_./) { |v| v[1]&.upcase } } unless options.nil?
631639
@bridge.install_app(path, options)
632640
end
633641

lib/appium_lib_core/common/wait.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,9 @@ def until(timeout: DEFAULT_TIMEOUT, interval: DEFAULT_INTERVAL, message: nil, ig
6262
end
6363

6464
msg = message_for timeout, message
65+
# steep:ignore:start
6566
msg += " (#{last_error.message})" if last_error
67+
# steep:ignore:end
6668

6769
raise TimeoutError, msg
6870
end
@@ -109,7 +111,9 @@ def until_true(timeout: DEFAULT_TIMEOUT, interval: DEFAULT_INTERVAL, message: ni
109111
end
110112

111113
msg = message_for timeout, message
114+
# steep:ignore:start
112115
msg += " (#{last_error.message})" if last_error
116+
# steep:ignore:end
113117

114118
raise TimeoutError, msg
115119
end

lib/appium_lib_core/common/ws/websocket.rb

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ def initialize(url:, protocols: nil, options: {})
4343
@endpoint = url
4444

4545
@ws_thread = Thread.new do
46+
# steep:ignore:start
4647
EM.run do
4748
@client ||= ::Faye::WebSocket::Client.new(url, protocols, options)
4849

@@ -62,6 +63,7 @@ def initialize(url:, protocols: nil, options: {})
6263
handle_close(close.code, close.reason)
6364
end
6465
end
66+
# steep:ignore:end
6567
end
6668
end
6769

@@ -120,7 +122,7 @@ def close(code: nil, reason: 'close from ruby_lib_core')
120122
# Default is just put a debug message.
121123
#
122124
def handle_open
123-
::Appium::Logger.debug %W(#{self.class} :open)
125+
::Appium::Logger.debug("#{self.class} :open")
124126
end
125127

126128
# Standard out by default
@@ -134,7 +136,7 @@ def handle_open
134136
# In general, users should override this handler to handle messages from the peer.
135137
#
136138
def handle_message_data(data)
137-
::Appium::Logger.debug %W(#{self.class} :message #{data})
139+
::Appium::Logger.debug("#{self.class} :message #{data}")
138140
$stdout << "#{data}\n"
139141
end
140142

@@ -145,7 +147,7 @@ def handle_message_data(data)
145147
# Default is just put a error message.
146148
#
147149
def handle_error
148-
::Appium::Logger.error %W(#{self.class} :error)
150+
::Appium::Logger.error("#{self.class} :error")
149151
end
150152

151153
#
@@ -156,9 +158,11 @@ def handle_error
156158
# The methods also clear +client+ instance and stop the eventmachine which is called in initialising this class.
157159
#
158160
def handle_close(code, reason)
159-
::Appium::Logger.debug %W(#{self.class} :close #{code} #{reason})
161+
::Appium::Logger.debug("#{self.class} :close #{code} #{reason}")
160162
@client = nil
163+
# steep:ignore:start
161164
EM.stop
165+
# steep:ignore:end
162166
end
163167
end # module WebSocket
164168
end # module Core

lib/appium_lib_core/driver.rb

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -602,12 +602,19 @@ def extend_for(device:, automation_name:) # rubocop:disable Metrics/CyclomaticCo
602602

603603
# @private
604604
def get_caps(opts)
605-
Core::Base::Capabilities.new(opts[:caps] || opts[:capabilities] || {})
605+
o = opts || {}
606+
607+
raw_caps = o[:caps] || o[:capabilities]
608+
caps_hash = raw_caps.is_a?(Hash) ? raw_caps : {}
609+
610+
Core::Base::Capabilities.new(caps_hash)
606611
end
607612

608-
# @private
609613
def get_appium_lib_opts(opts)
610-
opts[:appium_lib] || {}
614+
o = opts || {}
615+
616+
val = o[:appium_lib]
617+
val.is_a?(Hash) ? val : {}
611618
end
612619

613620
# @private
@@ -621,17 +628,21 @@ def get_app
621628
# Use @caps[:app] without modifications if the path isn't HTTP/S or local path.
622629
def set_app_path
623630
# FIXME: maybe `:app` should check `app` as well.
624-
return unless @caps && get_app && !get_app.empty?
631+
return unless @caps
632+
633+
app = get_app # for steep reason
634+
return unless app && app.empty?
625635

626636
uri_regex = defined?(URI::RFC2396_PARSER) ? URI::RFC2396_PARSER : URI::DEFAULT_PARSER
627-
return if get_app =~ uri_regex.make_regexp
637+
return if app =~ uri_regex.make_regexp
628638

629-
app_path = File.expand_path(get_app)
639+
# steep:ignore
640+
app_path = File.expand_path(app)
630641
@caps['app'] = if File.exist? app_path
631642
app_path
632643
else
633-
::Appium::Logger.warn("Use #{get_app} directly since #{app_path} does not exist.")
634-
get_app
644+
::Appium::Logger.warn("Use #{app} directly since #{app_path} does not exist.")
645+
app
635646
end
636647
end
637648

@@ -659,7 +670,7 @@ def set_appium_lib_specific_values(appium_lib_opts)
659670
def set_appium_device
660671
# https://code.google.com/p/selenium/source/browse/spec-draft.md?repo=mobile
661672
@device = get_cap 'platformName'
662-
return @device unless @device
673+
return unless @device
663674

664675
@device = convert_to_symbol(convert_downcase(@device))
665676
end

0 commit comments

Comments
 (0)