Skip to content

Commit 99a248d

Browse files
authored
fix: seleium 4.46 compatibility (#690)
* fix: selneium 4.46 compatibility * update steep
1 parent 77b9cca commit 99a248d

8 files changed

Lines changed: 40 additions & 6 deletions

File tree

appium_lib_core.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Gem::Specification.new do |spec|
2121
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
2222
spec.require_paths = ['lib']
2323

24-
spec.add_dependency 'selenium-webdriver', '~> 4.21', '< 4.46'
24+
spec.add_dependency 'selenium-webdriver', '~> 4.21'
2525

2626
spec.metadata['rubygems_mfa_required'] = 'true'
2727
end

lib/appium_lib_core/common/base/bridge.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,17 @@ class Bridge < ::Selenium::WebDriver::Remote::Bridge
4747
# No 'browserName' means the session is native appium connection
4848
APPIUM_NATIVE_BROWSER_NAME = 'appium'
4949

50+
# Selenium 4.46 moved server URL configuration from Bridge to the HTTP client.
51+
def initialize(url:, http_client: nil)
52+
if selenium_bridge_accepts_url?
53+
super
54+
else
55+
http_client ||= ::Selenium::WebDriver::Remote::Http::Default.new
56+
http_client.server_url = url
57+
super(http_client: http_client)
58+
end
59+
end
60+
5061
def browser
5162
@browser ||= begin
5263
name = @capabilities&.browser_name
@@ -137,6 +148,12 @@ def add_appium_prefix(capabilities)
137148

138149
private
139150

151+
def selenium_bridge_accepts_url?
152+
::Selenium::WebDriver::Remote::Bridge.instance_method(:initialize).parameters.any? do |_, name|
153+
name == :url
154+
end
155+
end
156+
140157
def camel_case(str_or_sym)
141158
str_or_sym.to_s.gsub(/_([a-z])/) { Regexp.last_match(1)&.upcase }
142159
end

lib/appium_lib_core/common/base/http_default.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,14 @@ def delete_additional_header(key)
6363
#
6464
# @return [URI] An instance of URI updated to. Returns default +server_url+ if some of arguments are +nil+
6565
def update_sending_request_to(scheme:, host:, port:, path:)
66-
return @server_url unless validate_url_param(scheme, host, port, path)
66+
return server_url unless validate_url_param(scheme, host, port, path)
6767

6868
# Add / if 'path' does not have it
6969
path = "/#{path}" unless path.start_with?('/')
7070
path = "#{path}/" unless path.end_with?('/')
7171

7272
@http = nil
73-
@server_url = URI.parse "#{scheme}://#{host}:#{port}#{path}"
73+
self.server_url = URI.parse "#{scheme}://#{host}:#{port}#{path}"
7474
end
7575

7676
private

sig/gems/selenium/bridge.rbs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ module Selenium
3030

3131
attr_reader capabilities: untyped
3232

33-
def initialize: (url: String | URI, ?http_client: untyped?) -> void
33+
def initialize: (?url: untyped, ?http_client: untyped?) -> void
3434

3535
def cancel_fedcm_dialog: -> nil
3636

sig/lib/appium_lib_core/common/base/bridge.rbs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ module Appium
4949
# No 'browserName' means the session is native appium connection
5050
APPIUM_NATIVE_BROWSER_NAME: "appium"
5151

52+
def initialize: (url: untyped, ?http_client: untyped?) -> void
53+
5254
def browser: () -> untyped
5355

5456
# Appium only.
@@ -103,6 +105,8 @@ module Appium
103105

104106
private
105107

108+
def selenium_bridge_accepts_url?: () -> bool
109+
106110
def camel_case: (untyped str_or_sym) -> untyped
107111

108112
def extension_prefix?: (untyped capability_name) -> untyped

sig/lib/appium_lib_core/common/base/driver.rbs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ module Appium
22
module Core
33
class Base
44
class Driver < Selenium::WebDriver::Driver
5+
extend Forwardable
6+
57
@wait_timeout: untyped
68

79
@wait_interval: untyped

sig/lib/appium_lib_core/driver.rbs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,16 @@ module Appium
7979
attr_reader path: String
8080

8181
def initialize: (Hash[String | Symbol, String] capabilities) -> void
82+
83+
def valid?: () -> bool
84+
85+
private
86+
87+
def resolve_addresses: (String host) -> Array[String]
88+
89+
def ip_literal?: (String host) -> bool
90+
91+
def disallowed?: (String ip) -> bool
8292
end
8393

8494
class Driver

test/unit/driver_test.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -463,8 +463,9 @@ def test_default_timeout_for_http_client_with_direct_no_supported_client
463463
core = ::Appium::Core.for(Caps.android_direct)
464464
driver = android_mock_create_session_w3c_direct_default_client.call(core)
465465

466-
assert_nil driver.send(:bridge).http.open_timeout
467-
assert_nil driver.send(:bridge).http.read_timeout
466+
default_http_client = Selenium::WebDriver::Remote::Http::Default.new
467+
assert_equal default_http_client.open_timeout, driver.send(:bridge).http.open_timeout
468+
assert_equal default_http_client.read_timeout, driver.send(:bridge).http.read_timeout
468469
uri = driver.send(:bridge).http.send(:server_url)
469470
assert core.direct_connect
470471
assert_equal 'http', uri.scheme

0 commit comments

Comments
 (0)