diff --git a/lib/appium_lib_core.rb b/lib/appium_lib_core.rb index 77e8ce27..4a4220d5 100644 --- a/lib/appium_lib_core.rb +++ b/lib/appium_lib_core.rb @@ -22,43 +22,6 @@ require_relative 'appium_lib_core/support/event_firing_bridge' module Appium - # convert the top level keys to symbols. - # - # @param [Hash] hash Hash value to make symbolise - # - # @example - # - # opts = Appium.symbolize_keys(opts) - # - def self.symbolize_keys(hash, nested: false, enable_deprecation_msg: true) - # FIXME: As https://github.com/appium/ruby_lib/issues/945, we must remove this implicit string to symbol. - # But appium_lib_core's some capability handling expect to be symbol, so we should test to remove - # the methods which expect the symbol first. - raise ::Appium::Core::Error::ArgumentError, 'symbolize_keys requires a hash' unless hash.is_a? Hash - - hash.each_with_object({}) do |pair, acc| - key = begin - if enable_deprecation_msg && !(pair[0].is_a? Symbol) - ::Appium::Logger.warn("[Deprecation] The key '#{pair[0]}' must be a symbol while currently it " \ - "is #{pair[0].class.name}. Please define the key as a Symbol. " \ - 'Converting it to Symbol for now.') - end - - pair[0].to_sym - rescue StandardError => e - ::Appium::Logger.warn(e.message) - pair[0] - end - - value = pair[1] - acc[key] = if nested - value.is_a?(Hash) ? symbolize_keys(value, nested: false, enable_deprecation_msg: false) : value - else - value - end - end - end - module Core # @see Appium::Core::Driver.for def self.for(opts = {}) diff --git a/lib/appium_lib_core/common/base/capabilities.rb b/lib/appium_lib_core/common/base/capabilities.rb index 7683769c..e7f26bba 100644 --- a/lib/appium_lib_core/common/base/capabilities.rb +++ b/lib/appium_lib_core/common/base/capabilities.rb @@ -24,14 +24,14 @@ class Capabilities < ::Selenium::WebDriver::Remote::Capabilities # standard options like chrome and firefox etc. So, the implementation should differ from # other browsers. But here should inherit `Options` to follow Selenium. - # Method override - # FIXME: when we drop "symbolize_keys", this can be removed. + # Override Selenium's convert_key to prevent camelCase conversion. + # Appium capability names should be preserved as-is (e.g., :some_capability stays "some_capability", + # not converted to "someCapability" as Selenium's default would do). def convert_key(key) case key when String key.to_s when Symbol - # here do not convert to camel case key.to_s else raise ::Appium::Core::Error::ArgumentError, "expected String or Symbol, got #{key.inspect}:#{key.class}" diff --git a/lib/appium_lib_core/driver.rb b/lib/appium_lib_core/driver.rb index 165d687a..439db1ba 100644 --- a/lib/appium_lib_core/driver.rb +++ b/lib/appium_lib_core/driver.rb @@ -36,13 +36,12 @@ module Ios # This options affects only client side as :appium_lib key.
# Read {::Appium::Core::Driver} about each attribute class Options - attr_reader :custom_url, :default_wait, + attr_reader :custom_url, :port, :wait_timeout, :wait_interval, :listener, :direct_connect, :enable_idempotency_header def initialize(appium_lib_opts) @custom_url = appium_lib_opts.fetch :server_url, nil - @default_wait = appium_lib_opts.fetch :wait, nil @enable_idempotency_header = appium_lib_opts.fetch :enable_idempotency_header, true @direct_connect = appium_lib_opts.fetch :direct_connect, true @@ -133,11 +132,6 @@ class Driver # @return [String] attr_reader :custom_url - # Default wait time for elements to appear in Appium server side. - # Provide { appium_lib: { wait: 30 } } to {::Appium::Core.for} - # @return [Integer] - attr_reader :default_wait - # Appium's server port. 4723 is by default. Defaults to {::Appium::Core::Driver::DEFAULT_APPIUM_PORT}.
# Provide { appium_lib: { port: 8080 } } to {::Appium::Core.for}. # :custom_url is prior than :port if :custom_url is set. @@ -213,7 +207,6 @@ class Driver # }, # appium_lib: { # port: 8080, - # wait: 0, # wait_timeout: 20, # wait_interval: 0.3, # listener: nil, @@ -234,7 +227,6 @@ class Driver # }, # appium_lib: { # server_url: 'http://custom-host:8080/wd/hub', - # wait: 0, # wait_timeout: 20, # wait_interval: 0.3, # listener: nil, @@ -254,7 +246,6 @@ class Driver # app: '/path/to/MyiOS.app' # }, # appium_lib: { - # wait: 0, # wait_timeout: 20, # wait_interval: 0.3, # listener: nil, @@ -376,7 +367,6 @@ def setup_for_new_session(opts = {}) # app: '/path/to/MyiOS.app' # }, # appium_lib: { - # wait: 20, # wait_timeout: 20, # wait_interval: 0.3, # } @@ -430,8 +420,6 @@ def start_driver(server_url: nil, @http_client.delete_additional_header Appium::Core::Base::Http::RequestHeaders::KEYS[:idempotency] end - set_implicit_wait_by_default(@default_wait) - @driver end @@ -478,18 +466,6 @@ def get_http_client(http_client: nil, open_timeout: nil, read_timeout: nil) http_client || Appium::Core::Base::Http::Default.new(open_timeout: open_timeout, read_timeout: read_timeout) end - # Ignore setting default wait if the target driver has no implementation - def set_implicit_wait_by_default(wait) - return if @default_wait.nil? - - @driver.manage.timeouts.implicit_wait = wait - rescue ::Selenium::WebDriver::Error::UnknownError => e - raise ::Appium::Core::Error::ServerError, e.message unless e.message.include?('The operation requested is not yet implemented') - - ::Appium::Logger.debug(e.message) - {} - end - # Returns the server's version info. This method calls +driver.remote_status+ internally # # @return [Hash] @@ -652,8 +628,6 @@ def set_appium_lib_specific_values(appium_lib_opts) @custom_url ||= opts.custom_url # Keep existence capability if it's already provided @enable_idempotency_header = opts.enable_idempotency_header - @default_wait = opts.default_wait - @port = opts.port @wait_timeout = opts.wait_timeout diff --git a/sig/lib/appium_lib_core.rbs b/sig/lib/appium_lib_core.rbs index 7e9a4bbe..284ca4f3 100644 --- a/sig/lib/appium_lib_core.rbs +++ b/sig/lib/appium_lib_core.rbs @@ -1,7 +1,4 @@ module Appium - def self.symbolize_keys: (Hash[untyped, untyped] hash, ?nested: bool, ?enable_deprecation_msg: bool) - -> Hash[Symbol, untyped] - module Core def self.for: (Hash[Symbol, untyped] opts) -> Driver end diff --git a/sig/lib/appium_lib_core/driver.rbs b/sig/lib/appium_lib_core/driver.rbs index 894b0e00..9575c1fb 100644 --- a/sig/lib/appium_lib_core/driver.rbs +++ b/sig/lib/appium_lib_core/driver.rbs @@ -20,8 +20,6 @@ module Appium class Options @custom_url: String - @default_wait: Integer - @enable_idempotency_header: bool @direct_connect: bool @@ -36,8 +34,6 @@ module Appium attr_reader custom_url: String - attr_reader default_wait: Integer - attr_reader port: Integer attr_reader wait_timeout: Integer @@ -98,8 +94,6 @@ module Appium @enable_idempotency_header: bool - @default_wait: Integer - @port: Integer @wait_timeout: Integer @@ -124,8 +118,6 @@ module Appium attr_reader custom_url: String - attr_reader default_wait: Integer - attr_reader port: Integer DEFAULT_APPIUM_PORT: Integer @@ -167,8 +159,6 @@ module Appium def get_http_client: (?http_client: untyped?, ?open_timeout: untyped?, ?read_timeout: untyped?) -> untyped - def set_implicit_wait_by_default: (untyped wait) -> untyped - def appium_server_version: () -> Hash[String, String] private diff --git a/test/functional/android/webdriver/device_test.rb b/test/functional/android/webdriver/device_test.rb index 6d7faa22..f75858f4 100644 --- a/test/functional/android/webdriver/device_test.rb +++ b/test/functional/android/webdriver/device_test.rb @@ -117,7 +117,7 @@ def test_dismiss_alert def test_implicit_wait # checking no method error - assert(@driver.manage.timeouts.implicit_wait = @@core.default_wait) + assert(@driver.manage.timeouts.implicit_wait = 0) end # Not so stable on CI diff --git a/test/functional/android/webdriver/w3c_actions_test.rb b/test/functional/android/webdriver/w3c_actions_test.rb index 40afec64..6c3a21db 100644 --- a/test/functional/android/webdriver/w3c_actions_test.rb +++ b/test/functional/android/webdriver/w3c_actions_test.rb @@ -60,7 +60,7 @@ def test_tap_scroll @driver.find_element(:accessibility_id, 'Custom') end end - @driver.manage.timeouts.implicit_wait = @@core.default_wait + @driver.manage.timeouts.implicit_wait = 0 end def test_double_tap diff --git a/test/test_helper.rb b/test/test_helper.rb index b21ef360..1194ece8 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -353,7 +353,6 @@ def android(activity_name = nil) uiautomator2ServerLaunchTimeout: 60_000 # ms }, appium_lib: { - wait: 5, wait_timeout: 20, wait_interval: 1 } @@ -381,7 +380,6 @@ def android_direct { capabilities: android[:capabilities], appium_lib: { - wait: 30, wait_timeout: 20, wait_interval: 1, direct_connect: true @@ -497,10 +495,6 @@ def android_mock_create_session_w3c stub_request(:post, 'http://127.0.0.1:4723/session') .to_return(headers: HEADER, status: 200, body: response) - stub_request(:post, "#{SESSION}/timeouts") - .with(body: { implicit: 5_000 }.to_json) - .to_return(headers: HEADER, status: 200, body: { value: nil }.to_json) - driver = @core.start_driver assert_equal ::Appium::Core::Base::Driver, driver.class assert_equal ::Appium::Core::Base::Bridge, driver.bridge.class @@ -516,24 +510,6 @@ def android_mock_create_session_w3c }, times: 1 ) - - assert_requested( - :post, - "#{SESSION}/timeouts", - headers: { - 'Content-Type' => 'application/json; charset=UTF-8', - 'User-Agent' => /appium\/ruby_lib_core\/.+/ - }, - body: { implicit: 5_000 }.to_json, - times: 1 - ) - assert_not_requested( - :post, - "#{SESSION}/timeouts", - headers: { 'X-Idempotency-Key' => /.+/ }, - body: { implicit: 5_000 }.to_json, - times: 1 - ) driver end @@ -554,10 +530,6 @@ def android_chrome_mock_create_session_w3c stub_request(:post, 'http://127.0.0.1:4723/session') .to_return(headers: HEADER, status: 200, body: response) - stub_request(:post, "#{SESSION}/timeouts") - .with(body: { implicit: 5_000 }.to_json) - .to_return(headers: HEADER, status: 200, body: { value: nil }.to_json) - driver = @core.start_driver assert_equal({}, driver.send(:bridge).http.additional_headers) @@ -571,24 +543,6 @@ def android_chrome_mock_create_session_w3c }, times: 1 ) - - assert_requested( - :post, - "#{SESSION}/timeouts", - headers: { - 'Content-Type' => 'application/json; charset=UTF-8', - 'User-Agent' => /appium\/ruby_lib_core\/.+/ - }, - body: { implicit: 5_000 }.to_json, - times: 1 - ) - assert_not_requested( - :post, - "#{SESSION}/timeouts", - headers: { 'X-Idempotency-Key' => /.+/ }, - body: { implicit: 5_000 }.to_json, - times: 1 - ) driver end diff --git a/test/unit/appium_lib_core_test.rb b/test/unit/appium_lib_core_test.rb index 264352f9..380e5b93 100644 --- a/test/unit/appium_lib_core_test.rb +++ b/test/unit/appium_lib_core_test.rb @@ -20,50 +20,6 @@ def test_version assert !::Appium::Core::VERSION.nil? end - # TODO: Should be removed in the future - def test_symbolize_keys - result = ::Appium.symbolize_keys({ 'a' => 1, b: 2 }) - assert_equal({ a: 1, b: 2 }, result) - end - - def test_not_symbolize_keys_nested1 - result = ::Appium.symbolize_keys( - { 'caps': { 'automationName' => 'xcuitest', platformName: :ios } }, nested: true - ) - assert_equal({ caps: { automationName: 'xcuitest', platformName: :ios } }, result) - end - - def test_not_symbolize_keys_nested2 - result = ::Appium.symbolize_keys( - { 'caps': { 'automationName' => 'xcuitest', platformName: :ios, other_caps: { 'something1': 1, something2: 2 } } }, - nested: true - ) - assert_equal( - { caps: { automationName: 'xcuitest', platformName: :ios, other_caps: { 'something1': 1, something2: 2 } } }, - result - ) - end - - def test_not_symbolize_keys_nested3 - result = ::Appium.symbolize_keys( - { 'caps': { 'automationName' => 'xcuitest', platformName: :ios, other_caps: { 'something1': 1, something2: 2 } } }, - nested: false - ) - assert_equal( - { caps: { 'automationName' => 'xcuitest', platformName: :ios, other_caps: { 'something1': 1, something2: 2 } } }, - result - ) - end - - # TODO: Should be removed in the future - def test_symbolize_keys_raise_argument_error - e = assert_raises ::Appium::Core::Error::ArgumentError do - ::Appium.symbolize_keys('no hash value') - end - - assert_equal 'symbolize_keys requires a hash', e.message - end - def test_core_instance_variables opts = { url: 'http://custom-host:8080/wd/hub/path', diff --git a/test/unit/driver_test.rb b/test/unit/driver_test.rb index c0e7ee0c..985fd9b1 100644 --- a/test/unit/driver_test.rb +++ b/test/unit/driver_test.rb @@ -112,10 +112,6 @@ def test_verify_appium_core_base_capabilities_create_capabilities_with_caps_stri assert_equal 'test/functional/app/UIKitCatalog-iphonesimulator.zip', caps['appium:app'] end - def test_default_wait - assert_equal 5, @core.default_wait - end - def test_default_timeout_for_http_client driver = android_mock_create_session @@ -159,15 +155,9 @@ def test_default_timeout_for_http_client_with_direct stub_request(:post, 'http://127.0.0.1:4723/session') .to_return(headers: HEADER, status: 200, body: response) - stub_request(:post, 'http://localhost:8888/wd/hub/session/1234567890/timeouts') - .with(body: { implicit: 30_000 }.to_json) - .to_return(headers: HEADER, status: 200, body: { value: nil }.to_json) - driver = core.start_driver assert_requested(:post, 'http://127.0.0.1:4723/session', times: 1) - assert_requested(:post, 'http://localhost:8888/wd/hub/session/1234567890/timeouts', - body: { implicit: 30_000 }.to_json, times: 1) driver end @@ -209,15 +199,9 @@ def test_default_timeout_for_http_client_with_direct_appium_prefix stub_request(:post, 'http://127.0.0.1:4723/session') .to_return(headers: HEADER, status: 200, body: response) - stub_request(:post, 'http://localhost:8888/wd/hub/session/1234567890/timeouts') - .with(body: { implicit: 30_000 }.to_json) - .to_return(headers: HEADER, status: 200, body: { value: nil }.to_json) - driver = core.start_driver assert_requested(:post, 'http://127.0.0.1:4723/session', times: 1) - assert_requested(:post, 'http://localhost:8888/wd/hub/session/1234567890/timeouts', - body: { implicit: 30_000 }.to_json, times: 1) driver end @@ -263,15 +247,9 @@ def test_default_timeout_for_http_client_with_direct_appium_prefix_prior_than_no stub_request(:post, 'http://127.0.0.1:4723/session') .to_return(headers: HEADER, status: 200, body: response) - stub_request(:post, 'http://localhost:8888/wd/hub/session/1234567890/timeouts') - .with(body: { implicit: 30_000 }.to_json) - .to_return(headers: HEADER, status: 200, body: { value: nil }.to_json) - driver = core.start_driver assert_requested(:post, 'http://127.0.0.1:4723/session', times: 1) - assert_requested(:post, 'http://localhost:8888/wd/hub/session/1234567890/timeouts', - body: { implicit: 30_000 }.to_json, times: 1) driver end @@ -312,15 +290,9 @@ def test_default_timeout_for_http_client_with_direct_no_path stub_request(:post, 'http://127.0.0.1:4723/session') .to_return(headers: HEADER, status: 200, body: response) - stub_request(:post, 'http://127.0.0.1:4723/session/1234567890/timeouts') - .with(body: { implicit: 30_000 }.to_json) - .to_return(headers: HEADER, status: 200, body: { value: nil }.to_json) - driver = core.start_driver assert_requested(:post, 'http://127.0.0.1:4723/session', times: 1) - assert_requested(:post, 'http://127.0.0.1:4723/session/1234567890/timeouts', - body: { implicit: 30_000 }.to_json, times: 1) driver end @@ -362,15 +334,9 @@ def test_default_timeout_for_http_client_with_direct_no_supported_client stub_request(:post, 'http://127.0.0.1:4723/session') .to_return(headers: HEADER, status: 200, body: response) - stub_request(:post, 'http://127.0.0.1:4723/session/1234567890/timeouts') - .with(body: { implicit: 30_000 }.to_json) - .to_return(headers: HEADER, status: 200, body: { value: nil }.to_json) - driver = core.start_driver http_client_ops: { http_client: Selenium::WebDriver::Remote::Http::Default.new } assert_requested(:post, 'http://127.0.0.1:4723/session', times: 1) - assert_requested(:post, 'http://127.0.0.1:4723/session/1234567890/timeouts', - body: { implicit: 30_000 }.to_json, times: 1) driver end @@ -408,15 +374,9 @@ def _android_mock_create_session_w3c(core) stub_request(:post, 'http://127.0.0.1:4723/session') .to_return(headers: HEADER, status: 200, body: response) - stub_request(:post, 'http://127.0.0.1:4723/session/1234567890/timeouts') - .with(body: { implicit: 5_000 }.to_json) - .to_return(headers: HEADER, status: 200, body: { value: nil }.to_json) - driver = core.start_driver assert_requested(:post, 'http://127.0.0.1:4723/session', times: 1) - assert_requested(:post, 'http://127.0.0.1:4723/session/1234567890/timeouts', - body: { implicit: 5_000 }.to_json, times: 1) driver end @@ -452,15 +412,9 @@ def _android_mock_create_session_w3c_with_custom_http_client(core) stub_request(:post, 'http://127.0.0.1:4723/session') .to_return(headers: HEADER, status: 200, body: response) - stub_request(:post, 'http://127.0.0.1:4723/session/1234567890/timeouts') - .with(body: { implicit: 5_000 }.to_json) - .to_return(headers: HEADER, status: 200, body: { value: nil }.to_json) - driver = core.start_driver http_client_ops: { http_client: Selenium::WebDriver::Remote::Http::Default.new } assert_requested(:post, 'http://127.0.0.1:4723/session', times: 1) - assert_requested(:post, 'http://127.0.0.1:4723/session/1234567890/timeouts', - body: { implicit: 5_000 }.to_json, times: 1) driver end @@ -527,15 +481,9 @@ def test_attach_to_an_existing_session stub_request(:post, 'http://127.0.0.1:4723/session') .to_return(headers: HEADER, status: 200, body: response) - stub_request(:post, 'http://localhost:8888/wd/hub/session/1234567890/timeouts') - .with(body: { implicit: 30_000 }.to_json) - .to_return(headers: HEADER, status: 200, body: { value: nil }.to_json) - driver = core.start_driver assert_requested(:post, 'http://127.0.0.1:4723/session', times: 1) - assert_requested(:post, 'http://localhost:8888/wd/hub/session/1234567890/timeouts', - body: { implicit: 30_000 }.to_json, times: 1) driver end