Skip to content

Commit a10f2d1

Browse files
authored
feat: allow :capabilities as argument (#266)
* feat: allow :capabilities as arg * tweak the test of tvos
1 parent 1b038c1 commit a10f2d1

File tree

4 files changed

+54
-13
lines changed

4 files changed

+54
-13
lines changed

CHANGELOG.md

+14
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,20 @@ Read `release_notes.md` for commit level details.
55
## [Unreleased]
66

77
### Enhancements
8+
- `capabilities:` is available in addition to `desired_capabilities:` and `caps:` as a capability
9+
```ruby
10+
# case 1
11+
opts = { caps: { }, appium_lib: { } }
12+
@driver = Appium::Core.for(opts).start_driver
13+
14+
# case 2
15+
opts = { capabilities: { }, appium_lib: { } }
16+
@driver = Appium::Core.for(opts).start_driver
17+
18+
# case 3
19+
opts = { desired_capabilities: { }, appium_lib: { } }
20+
@driver = Appium::Core.for(opts).start_driver
21+
```
822

923
### Bug fixes
1024

lib/appium_lib_core/driver.rb

+13-7
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,9 @@ class Driver
182182

183183
# Creates a new driver and extend particular methods
184184
# @param [Hash] opts A options include capabilities for the Appium Server and for the client.
185-
# @option opts [Hash] :caps Appium capabilities. Prior than :desired_capabilities
185+
# @option opts [Hash] :caps Appium capabilities.
186+
# @option opts [Hash] :capabilities The same as :caps.
187+
# This param is for compatibility with Selenium WebDriver format
186188
# @option opts [Hash] :desired_capabilities The same as :caps.
187189
# This param is for compatibility with Selenium WebDriver format
188190
# @option opts [Appium::Core::Options] :appium_lib Capabilities affect only ruby client
@@ -195,8 +197,8 @@ class Driver
195197
#
196198
# # format 1
197199
# @core = Appium::Core.for caps: {...}, appium_lib: {...}
198-
# # format 2. 'desired_capabilities:' is also available instead of 'caps:'. Either is fine.
199-
# @core = Appium::Core.for url: "http://127.0.0.1:8080/wd/hub", desired_capabilities: {...}, appium_lib: {...}
200+
# # format 2. 'capabilities:' or 'desired_capabilities:' is also available instead of 'caps:'.
201+
# @core = Appium::Core.for url: "http://127.0.0.1:8080/wd/hub", capabilities: {...}, appium_lib: {...}
200202
# # format 3. 'appium_lib: {...}' can be blank
201203
# @core = Appium::Core.for url: "http://127.0.0.1:8080/wd/hub", desired_capabilities: {...}
202204
#
@@ -226,9 +228,9 @@ class Driver
226228
# @core.start_driver # Connect to 'http://127.0.0.1:8080/wd/hub' because of 'port: 8080'
227229
#
228230
# # Start iOS driver with .zip file over HTTP
229-
# # 'desired_capabilities:' is also available instead of 'caps:'. Either is fine.
231+
# # 'desired_capabilities:' or 'capabilities:' is also available instead of 'caps:'. Either is fine.
230232
# opts = {
231-
# desired_capabilities: {
233+
# capabilities: {
232234
# platformName: :ios,
233235
# platformVersion: '11.0',
234236
# deviceName: 'iPhone Simulator',
@@ -541,7 +543,10 @@ def extend_for(device:, automation_name:)
541543
def validate_keys(opts)
542544
flatten_ops = flatten_hash_keys(opts)
543545

544-
raise Error::NoCapabilityError unless opts.member?(:caps) || opts.member?(:desired_capabilities)
546+
# FIXME: Remove 'desired_capabilities' in the next major Selenium update
547+
unless opts.member?(:caps) || opts.member?(:capabilities) || opts.member?(:desired_capabilities)
548+
raise Error::NoCapabilityError
549+
end
545550

546551
if !opts.member?(:appium_lib) && flatten_ops.member?(:appium_lib)
547552
raise Error::CapabilityStructureError, 'Please check the value of appium_lib in the capability'
@@ -562,7 +567,8 @@ def flatten_hash_keys(hash, flatten_keys_result = [])
562567

563568
# @private
564569
def get_caps(opts)
565-
Core::Base::Capabilities.create_capabilities(opts[:caps] || opts[:desired_capabilities] || {})
570+
# FIXME: Remove 'desired_capabilities' in the next major Selenium update
571+
Core::Base::Capabilities.create_capabilities(opts[:caps] || opts[:capabilities] || opts[:desired_capabilities] || {})
566572
end
567573

568574
# @private

test/functional/ios/tv_driver_test.rb

+2-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ def test_launch_app
5555
assert result
5656

5757
e1 = @driver.switch_to.active_element
58-
assert_equal 'Settings', e1.label
58+
label = e1.label
59+
assert %w(Settings Music).include? label
5960
end
6061
end
6162
end

test/unit/driver_test.rb

+25-5
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,10 @@ def setup
2323
end
2424

2525
class ExampleDriver
26+
# for test
27+
attr_reader :core
2628
def initialize(opts)
27-
::Appium::Core.for(opts)
29+
@core = ::Appium::Core.for(opts)
2830
end
2931
end
3032

@@ -37,13 +39,31 @@ def test_no_caps
3739
end
3840

3941
def test_with_caps
40-
opts = { caps: {} }
41-
refute_nil ExampleDriver.new(opts)
42+
opts = { caps: { automationName: 'xcuitest' } }
43+
driver = ExampleDriver.new(opts)
44+
refute_nil driver
45+
assert_equal driver.core.caps[:automationName], 'xcuitest'
46+
end
47+
48+
def test_with_capabilities
49+
opts = { capabilities: { automationName: 'xcuitest' } }
50+
driver = ExampleDriver.new(opts)
51+
refute_nil driver
52+
assert_equal driver.core.caps[:automationName], 'xcuitest'
53+
end
54+
55+
def test_with_desired_capabilities
56+
opts = { desired_capabilities: { automationName: 'xcuitest' } }
57+
driver = ExampleDriver.new(opts)
58+
refute_nil driver
59+
assert_equal driver.core.caps[:automationName], 'xcuitest'
4260
end
4361

4462
def test_with_caps_and_appium_lib
45-
opts = { caps: {}, appium_lib: {} }
46-
refute_nil ExampleDriver.new(opts)
63+
opts = { caps: { automationName: 'xcuitest' }, appium_lib: {} }
64+
driver = ExampleDriver.new(opts)
65+
refute_nil driver
66+
assert_equal driver.core.caps[:automationName], 'xcuitest'
4767
end
4868

4969
def test_with_caps_and_wrong_appium_lib

0 commit comments

Comments
 (0)