Skip to content

Commit 0b3c45c

Browse files
authored
feat: do not restrict options in install_app (#361)
* feat: do not restric options in install_app * fix rubocop * tweak gsub * use ** * add description
1 parent eb4471a commit 0b3c45c

File tree

3 files changed

+22
-30
lines changed

3 files changed

+22
-30
lines changed

lib/appium_lib_core/common/base/driver.rb

+15-13
Original file line numberDiff line numberDiff line change
@@ -609,7 +609,9 @@ def background_app(duration = 0)
609609
@bridge.background_app(duration)
610610
end
611611

612-
# Install the given app onto the device
612+
# Install the given app onto the device.
613+
# Each options can be snake-case or camel-case. Snake-cases will be converted to camel-case
614+
# as options value.
613615
#
614616
# @param [String] path The absolute local path or remote http URL to an .ipa or .apk file,
615617
# or a .zip containing one of these.
@@ -623,26 +625,26 @@ def background_app(duration = 0)
623625
# @param [Boolean] grant_permissions Only for Android. whether to automatically grant application permissions
624626
# on Android 6+ after the installation completes. +false+ by default
625627
#
628+
# Other parameters such as https://github.com/appium/appium-xcuitest-driver#mobile-installapp also can be set.
629+
# Then, arguments in snake case will be camel case as its request parameters.
630+
#
626631
# @example
627632
#
628633
# @driver.install_app("/path/to/test.apk")
629634
# @driver.install_app("/path/to/test.apk", replace: true, timeout: 20000, allow_test_packages: true,
630635
# use_sdcard: false, grant_permissions: false)
636+
# @driver.install_app("/path/to/test.ipa", timeoutMs: 20000)
631637
#
632-
def install_app(path,
633-
replace: nil,
634-
timeout: nil,
635-
allow_test_packages: nil,
636-
use_sdcard: nil,
637-
grant_permissions: nil)
638-
@bridge.install_app(path,
639-
replace: replace,
640-
timeout: timeout,
641-
allow_test_packages: allow_test_packages,
642-
use_sdcard: use_sdcard,
643-
grant_permissions: grant_permissions)
638+
def install_app(path, **options)
639+
options = options.transform_keys { |key| key.to_s.gsub(/_./) { |v| v[1].upcase } } unless options.nil?
640+
@bridge.install_app(path, options)
644641
end
645642

643+
# def capitalize(s)
644+
# chars =
645+
# chars[1:].map(&:capitalize).join
646+
# end
647+
646648
# @param [Strong] app_id BundleId for iOS or package name for Android
647649
# @param [Boolean] keep_data Only for Android. Whether to keep application data and caches after it is uninstalled.
648650
# +false+ by default

lib/appium_lib_core/common/device/app_management.rb

+2-14
Original file line numberDiff line numberDiff line change
@@ -39,21 +39,9 @@ def background_app(duration = 0)
3939
raise NotImplementedError
4040
end
4141

42-
def install_app(path,
43-
replace: nil,
44-
timeout: nil,
45-
allow_test_packages: nil,
46-
use_sdcard: nil,
47-
grant_permissions: nil)
42+
def install_app(path, options = {})
4843
args = { appPath: path }
49-
50-
args[:options] = {} if options?(replace, timeout, allow_test_packages, use_sdcard, grant_permissions)
51-
52-
args[:options][:replace] = replace unless replace.nil?
53-
args[:options][:timeout] = timeout unless timeout.nil?
54-
args[:options][:allowTestPackages] = allow_test_packages unless allow_test_packages.nil?
55-
args[:options][:useSdcard] = use_sdcard unless use_sdcard.nil?
56-
args[:options][:grantPermissions] = grant_permissions unless grant_permissions.nil?
44+
args[:options] = options unless options.empty?
5745

5846
execute :install_app, {}, args
5947
end

test/unit/android/device/w3c/app_management_test.rb

+5-3
Original file line numberDiff line numberDiff line change
@@ -135,10 +135,11 @@ def test_install_app_with_params
135135
.with(body: { appPath: 'app_path',
136136
options: {
137137
replace: true,
138-
timeout: 20_000,
138+
timeout: 20_000, # for Android
139139
allowTestPackages: true,
140140
useSdcard: false,
141-
grantPermissions: false
141+
grantPermissions: false,
142+
timeoutMs: 10_000 # for iOS
142143
} }.to_json)
143144
.to_return(headers: HEADER, status: 200, body: { value: '' }.to_json)
144145

@@ -147,7 +148,8 @@ def test_install_app_with_params
147148
timeout: 20_000,
148149
allow_test_packages: true,
149150
use_sdcard: false,
150-
grant_permissions: false
151+
grantPermissions: false,
152+
timeout_ms: 10_000
151153

152154
assert_requested(:post, "#{SESSION}/appium/device/install_app", times: 1)
153155
end

0 commit comments

Comments
 (0)