From 1b67fad49d1a18424007df3acc283a3631840cd1 Mon Sep 17 00:00:00 2001 From: hoanle0126 Date: Mon, 26 Oct 2026 15:35:14 +0700 Subject: [PATCH 1/2] fix: require error definitions, use next in HTMLElements#result, and fix Driver#log_event= error raising --- lib/appium_lib/appium.rb | 1 + lib/appium_lib/common/helper.rb | 2 +- lib/appium_lib/driver.rb | 4 ++-- test/regression_test.rb | 15 +++++++++++++++ 4 files changed, 19 insertions(+), 3 deletions(-) diff --git a/lib/appium_lib/appium.rb b/lib/appium_lib/appium.rb index 5664459b..51110299 100644 --- a/lib/appium_lib/appium.rb +++ b/lib/appium_lib/appium.rb @@ -19,6 +19,7 @@ require 'appium_lib_core' # base +require_relative 'error' require_relative 'driver' require_relative 'sauce_labs' diff --git a/lib/appium_lib/common/helper.rb b/lib/appium_lib/common/helper.rb index 09954859..a457b7cb 100644 --- a/lib/appium_lib/common/helper.rb +++ b/lib/appium_lib/common/helper.rb @@ -233,7 +233,7 @@ def result "#{string} #{attr[0]}: #{attr1}\n" end - return r if attr_string.nil? || attr_string.empty? + next r if attr_string.nil? || attr_string.empty? "#{r}\n#{name}\n#{attr_string}" end diff --git a/lib/appium_lib/driver.rb b/lib/appium_lib/driver.rb index 19eda7c0..711c1891 100644 --- a/lib/appium_lib/driver.rb +++ b/lib/appium_lib/driver.rb @@ -888,9 +888,9 @@ def log_event(vendor:, event:) end def log_event=(log_event) - raise if @driver.nil? + raise NoDriverInstanceError if @driver.nil? unless log_event.is_a?(Hash) - raise ::Appium::Core::Error::ArgumentError('log_event should be Hash like { vendor: "appium", event: "funEvent"}') + raise ::Appium::Core::Error::ArgumentError, 'log_event should be Hash like { vendor: "appium", event: "funEvent"}' end @driver.logs.event vendor: log_event[:vendor], event: log_event[:event] diff --git a/test/regression_test.rb b/test/regression_test.rb index c91dc06a..1741091b 100644 --- a/test/regression_test.rb +++ b/test/regression_test.rb @@ -142,6 +142,21 @@ def stub_driver.lazy_load_strings assert_equal expected, doc.result end + def test_html_elements_result_continues_after_attribute_free_elements + parser = Nokogiri::HTML::SAX::Parser.new(Appium::Common::HTMLElements.new) + parser.parse('
Sign in') + + assert_equal "\na\n href: /login\n text: Sign in\n", parser.document.result + end + + def test_log_event_writer_raises_no_driver_and_argument_errors + driver = build_driver + assert_raises(Appium::NoDriverInstanceError) { driver.log_event = { vendor: 'appium', event: 'funEvent' } } + + driver.instance_variable_set(:@driver, Object.new) + assert_raises(Appium::Core::Error::ArgumentError) { driver.log_event = 'invalid' } + end + private def build_driver From fad87468286603eb53cbd4ee72bfa1ff146cb2bf Mon Sep 17 00:00:00 2001 From: Nacy Dev Date: Tue, 27 Oct 2026 18:31:20 +0700 Subject: [PATCH 2/2] fix: qualify ::ArgumentError in method promotion rescue clauses --- lib/appium_lib/appium.rb | 4 ++-- test/regression_test.rb | 30 ++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/lib/appium_lib/appium.rb b/lib/appium_lib/appium.rb index 51110299..de3d2610 100644 --- a/lib/appium_lib/appium.rb +++ b/lib/appium_lib/appium.rb @@ -174,7 +174,7 @@ def promote_singleton_appium_methods(modules, driver = $driver) const.send(:define_singleton_method, m) do |*args, **kwargs, &block| super(*args, **kwargs, &block) # promote.rb - rescue NoMethodError, ArgumentError + rescue NoMethodError, ::ArgumentError driver.send m, *args, **kwargs, &block if driver.respond_to?(m) end end @@ -230,7 +230,7 @@ def promote_appium_methods(class_array, driver = $driver) # minitest also defines a name method, # so rescue argument error # and call the name method on $driver - rescue NoMethodError, ArgumentError + rescue NoMethodError, ::ArgumentError if args.size == 1 && args.first.is_a?(Hash) # To prevent warnings by keyword arguments (for Ruby 2.7 and 3) driver.send method, **args.first, &block if driver.respond_to?(method) diff --git a/test/regression_test.rb b/test/regression_test.rb index 1741091b..87a94f67 100644 --- a/test/regression_test.rb +++ b/test/regression_test.rb @@ -44,6 +44,36 @@ def driver.back assert_equal :inherited, child.new.back end + def test_promote_falls_back_to_driver_on_arity_mismatch + parent = Class.new do + def name + :parent_name + end + end + child = Class.new(parent) + driver = Object.new + def driver.name(value) + :"driver_#{value}" + end + + Appium.promote_appium_methods(child, driver) + assert_equal :parent_name, child.new.name + assert_equal :driver_arg, child.new.name(:arg) + + base_mod = Module.new do + def name + :mod_name + end + end + target_mod = Module.new do + extend base_mod + end + + Appium.promote_singleton_appium_methods([target_mod], driver) + assert_equal :mod_name, target_mod.name + assert_equal :driver_arg, target_mod.name(:arg) + end + def test_promote_again_uses_new_driver target = Class.new first = Object.new