Skip to content

Commit 27047ee

Browse files
authored
fix instance variables of device and automation_name (#570)
* fix instance variables of device and automation_name * fix type * refactoring a bit * add tests more
1 parent 7528eae commit 27047ee

File tree

3 files changed

+104
-10
lines changed

3 files changed

+104
-10
lines changed

lib/appium_lib_core/driver.rb

+19-10
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ def initialize(capabilities)
104104
class Driver
105105
include Waitable
106106

107-
# Selenium webdriver capabilities
107+
# Selenium webdriver capabilities, but the value is provided capabilities basis.
108108
# @return [Core::Base::Capabilities]
109109
attr_reader :caps
110110

@@ -125,7 +125,7 @@ class Driver
125125

126126
# Automation name sent to appium server or received by server.<br>
127127
# If automation_name is <code>nil</code>, it is not set both client side and server side.
128-
# @return [Hash]
128+
# @return [Symbol]
129129
attr_reader :automation_name
130130

131131
# Custom URL for the selenium server. If set this attribute, ruby_lib_core try to handshake to the custom url.<br>
@@ -634,7 +634,7 @@ def get_appium_lib_opts(opts)
634634

635635
# @private
636636
def get_app
637-
@caps[:app] || @caps['app']
637+
get_cap 'app'
638638
end
639639

640640
# @private
@@ -678,17 +678,17 @@ def set_appium_lib_specific_values(appium_lib_opts)
678678
# @private
679679
def set_appium_device
680680
# https://code.google.com/p/selenium/source/browse/spec-draft.md?repo=mobile
681-
@device = @caps[:platformName] || @caps['platformName']
681+
@device = get_cap 'platformName'
682682
return @device unless @device
683683

684-
@device = convert_downcase @device
684+
@device = convert_to_symbol(convert_downcase(@device))
685685
end
686686

687687
# @private
688688
def set_automation_name
689-
candidate = @caps[:automationName] || @caps['automationName']
689+
candidate = get_cap 'automationName'
690690
@automation_name = candidate if candidate
691-
@automation_name = convert_downcase @automation_name if @automation_name
691+
@automation_name = convert_to_symbol(convert_downcase(@automation_name)) if @automation_name
692692
end
693693

694694
# @private
@@ -700,9 +700,18 @@ def convert_downcase(value)
700700
def set_automation_name_if_nil
701701
return unless @automation_name.nil?
702702

703-
@automation_name = if @driver.capabilities['automationName']
704-
@driver.capabilities['automationName'].downcase.strip.intern
705-
end
703+
automation_name = if @driver.capabilities['automationName']
704+
@driver.capabilities['automationName'].downcase.strip.intern
705+
end
706+
@automation_name = convert_to_symbol automation_name
707+
end
708+
709+
def get_cap(name)
710+
name_with_prefix = "appium:#{name}"
711+
@caps[convert_to_symbol name] ||
712+
@caps[name] ||
713+
@caps[convert_to_symbol name_with_prefix] ||
714+
@caps[name_with_prefix]
706715
end
707716
end # class Driver
708717
end # module Core

test/unit/appium_lib_core_test.rb

+53
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,59 @@ def test_symbolize_keys_raise_argument_error
6464
assert_equal 'symbolize_keys requires a hash', e.message
6565
end
6666

67+
def test_core_instance_variables
68+
opts = {
69+
url: 'http://custom-host:8080/wd/hub.com',
70+
caps: {
71+
platformName: :ios,
72+
platformVersion: '11.0',
73+
deviceName: 'iPhone Simulator',
74+
automationName: 'XCUITest',
75+
app: '/path/to/MyiOS.app'
76+
}
77+
}
78+
@core = Appium::Core.for(opts)
79+
assert_equal 'http://custom-host:8080/wd/hub.com', @core.custom_url
80+
81+
assert_equal :ios, @core.device
82+
assert_equal :xcuitest, @core.automation_name
83+
end
84+
85+
def test_core_instance_variables_with_appium_prefix_hash
86+
opts = {
87+
url: 'http://custom-host:8080/wd/hub.com',
88+
caps: {
89+
'platformName': 'ios',
90+
'appium:platformVersion': '11.0',
91+
'appium:deviceName': 'iPhone Simulator',
92+
'appium:automationName': 'XCUITest',
93+
'appium:app': '/path/to/MyiOS.app'
94+
}
95+
}
96+
@core = Appium::Core.for(opts)
97+
assert_equal 'http://custom-host:8080/wd/hub.com', @core.custom_url
98+
99+
assert_equal :ios, @core.device
100+
assert_equal :xcuitest, @core.automation_name
101+
end
102+
103+
def test_core_instance_variables_with_appium_prefix_string
104+
opts = {
105+
url: 'http://custom-host:8080/wd/hub.com',
106+
caps: {
107+
'platformName' => 'ios',
108+
'appium:platformVersion' => '11.0',
109+
'appium:deviceName' => 'iPhone Simulator',
110+
'appium:automationName' => 'XCUITest',
111+
'appium:app' => '/path/to/MyiOS.app'
112+
}
113+
}
114+
@core = Appium::Core.for(opts)
115+
assert_equal 'http://custom-host:8080/wd/hub.com', @core.custom_url
116+
117+
assert_equal :ios, @core.device
118+
assert_equal :xcuitest, @core.automation_name
119+
end
67120
def test_url_param
68121
opts = {
69122
url: 'http://custom-host:8080/wd/hub.com',

test/unit/driver_test.rb

+32
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,38 @@ def test_verify_appium_core_base_capabilities_create_capabilities
7979
assert_equal 'someCapability2', caps[:someCapability2]
8080
end
8181

82+
def test_verify_appium_core_base_capabilities_create_capabilities_with_caps_hash
83+
caps = ::Appium::Core::Base::Capabilities.new(platformName: 'ios',
84+
'appium:platformVersion': '11.4',
85+
'appium:automationName': 'XCUITest',
86+
'appium:app': 'test/functional/app/UICatalog.app.zip')
87+
88+
caps_with_json = JSON.parse(caps.to_json)
89+
assert_equal 'ios', caps_with_json['platformName']
90+
assert_equal 'XCUITest', caps_with_json['appium:automationName']
91+
assert_equal 'test/functional/app/UICatalog.app.zip', caps_with_json['appium:app']
92+
93+
assert_equal 'ios', caps[:platformName]
94+
assert_equal 'XCUITest', caps[:'appium:automationName']
95+
assert_equal 'test/functional/app/UICatalog.app.zip', caps[:'appium:app']
96+
end
97+
98+
def test_verify_appium_core_base_capabilities_create_capabilities_with_caps_string
99+
caps = ::Appium::Core::Base::Capabilities.new('platformName' => 'ios',
100+
'appium:platformVersion' => '11.4',
101+
'appium:automationName' => 'XCUITest',
102+
'appium:app' => 'test/functional/app/UICatalog.app.zip')
103+
104+
caps_with_json = JSON.parse(caps.to_json)
105+
assert_equal 'ios', caps_with_json['platformName']
106+
assert_equal 'XCUITest', caps_with_json['appium:automationName']
107+
assert_equal 'test/functional/app/UICatalog.app.zip', caps_with_json['appium:app']
108+
109+
assert_equal 'ios', caps['platformName']
110+
assert_equal 'XCUITest', caps['appium:automationName']
111+
assert_equal 'test/functional/app/UICatalog.app.zip', caps['appium:app']
112+
end
113+
82114
def test_default_wait
83115
assert_equal 5, @core.default_wait
84116
end

0 commit comments

Comments
 (0)