Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 0 additions & 37 deletions lib/appium_lib_core.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {})
Expand Down
6 changes: 3 additions & 3 deletions lib/appium_lib_core/common/base/capabilities.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down
28 changes: 1 addition & 27 deletions lib/appium_lib_core/driver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,12 @@ module Ios
# This options affects only client side as <code>:appium_lib</code> key.<br>
# 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
Expand Down Expand Up @@ -133,11 +132,6 @@ class Driver
# @return [String]
attr_reader :custom_url

# Default wait time for elements to appear in Appium server side.
# Provide <code>{ appium_lib: { wait: 30 } }</code> 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}.<br>
# Provide <code>{ appium_lib: { port: 8080 } }</code> to {::Appium::Core.for}.
# <code>:custom_url</code> is prior than <code>:port</code> if <code>:custom_url</code> is set.
Expand Down Expand Up @@ -213,7 +207,6 @@ class Driver
# },
# appium_lib: {
# port: 8080,
# wait: 0,
# wait_timeout: 20,
# wait_interval: 0.3,
# listener: nil,
Expand All @@ -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,
Expand All @@ -254,7 +246,6 @@ class Driver
# app: '/path/to/MyiOS.app'
# },
# appium_lib: {
# wait: 0,
# wait_timeout: 20,
# wait_interval: 0.3,
# listener: nil,
Expand Down Expand Up @@ -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,
# }
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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
Expand Down
3 changes: 0 additions & 3 deletions sig/lib/appium_lib_core.rbs
Original file line number Diff line number Diff line change
@@ -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
Expand Down
10 changes: 0 additions & 10 deletions sig/lib/appium_lib_core/driver.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ module Appium
class Options
@custom_url: String

@default_wait: Integer

@enable_idempotency_header: bool

@direct_connect: bool
Expand All @@ -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
Expand Down Expand Up @@ -98,8 +94,6 @@ module Appium

@enable_idempotency_header: bool

@default_wait: Integer

@port: Integer

@wait_timeout: Integer
Expand All @@ -124,8 +118,6 @@ module Appium

attr_reader custom_url: String

attr_reader default_wait: Integer

attr_reader port: Integer

DEFAULT_APPIUM_PORT: Integer
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/functional/android/webdriver/device_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/functional/android/webdriver/w3c_actions_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
46 changes: 0 additions & 46 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,6 @@ def android(activity_name = nil)
uiautomator2ServerLaunchTimeout: 60_000 # ms
},
appium_lib: {
wait: 5,
wait_timeout: 20,
wait_interval: 1
}
Expand Down Expand Up @@ -381,7 +380,6 @@ def android_direct
{
capabilities: android[:capabilities],
appium_lib: {
wait: 30,
wait_timeout: 20,
wait_interval: 1,
direct_connect: true
Expand Down Expand Up @@ -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
Expand All @@ -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

Expand All @@ -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)
Expand All @@ -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

Expand Down
44 changes: 0 additions & 44 deletions test/unit/appium_lib_core_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
Loading