@@ -49,7 +49,7 @@ module Device
49
49
50
50
# @!method is_keyboard_shown
51
51
# Get whether keyboard is displayed or not.
52
- # @return [Bool ] Return true if keyboard is shown. Return false if keyboard is hidden.
52
+ # @return [Boolean ] Return true if keyboard is shown. Return false if keyboard is hidden.
53
53
#
54
54
# @example
55
55
# @driver.is_keyboard_shown # false
@@ -142,25 +142,37 @@ module Device
142
142
## With arguments
143
143
####
144
144
145
- # @!method install_app(path)
145
+ # @!method install_app(path, replace: nil, timeout: nil, allow_test_packages: nil, use_sdcard: nil, grant_permissions: nil )
146
146
# Install the given app onto the device
147
147
#
148
+ # @param [String] path The absolute local path or remote http URL to an .ipa or .apk file, or a .zip containing one of these.
149
+ # @param [Boolean] replace: Only for Android. Whether to reinstall/upgrade the package if it is already present on the device under test. `true` by default
150
+ # @param [Integer] timeout: Only for Android. How much time to wait for the installation to complete. 60000ms by default.
151
+ # @param [Boolean] allow_test_packages: Only for Android. Whether to allow installation of packages marked as test in the manifest. `false` by default
152
+ # @param [Boolean] use_sdcard: Only for Android. Whether to use the SD card to install the app. `false` by default
153
+ # @param [Boolean] grant_permissions: Only for Android. whether to automatically grant application permissions on Android 6+ after the installation completes. `false` by default
154
+ #
148
155
# @example
149
156
#
150
157
# @driver.install_app("/path/to/test.apk")
158
+ # @driver.install_app("/path/to/test.apk", replace: true, timeout: 20000, allow_test_packages: true, use_sdcard: false, grant_permissions: false)
151
159
#
152
160
153
- # @!method remove_app(app_id)
154
- # Install the given app onto the device
161
+ # @!method remove_app(app_id, keep_data: nil, timeout: nil)
162
+ #
163
+ # @param [Strong] app_id BundleId for iOS or package name for Android
164
+ # @param [Boolean] keep_data: Only for Android. Whether to keep application data and caches after it is uninstalled. `false` by default
165
+ # @param [Integer] timeout: Only for Android. How much time to wait for the uninstall to complete. 20000ms by default.
155
166
#
156
167
# @example
157
168
#
158
169
# @driver.remove_app("io.appium.bundle")
170
+ # @driver.remove_app("io.appium.bundle", keep_data: false, timeout, 10000)
159
171
#
160
172
161
173
# @!method app_installed?(app_id)
162
174
# Check whether the specified app is installed on the device
163
- # @return [bool ]
175
+ # @return [Boolean ]
164
176
#
165
177
# @example
166
178
#
@@ -169,11 +181,15 @@ module Device
169
181
170
182
# @!method terminate_app(app_id)
171
183
# Terminate the specified app.
172
- # @return [bool]
184
+ #
185
+ # @param [Strong] app_id BundleId for iOS or package name for Android
186
+ # @param [Integer] timeout: Only for Android. How much time to wait for the application termination to complete. 500ms by default.
187
+ # @return [Boolean]
173
188
#
174
189
# @example
175
190
#
176
191
# @driver.terminate_app("io.appium.bundle") # true
192
+ # @driver.terminate_app("io.appium.bundle", timeout: 500)
177
193
#
178
194
179
195
# @!method activate_app(app_id)
@@ -187,11 +203,11 @@ module Device
187
203
188
204
# Get the status of an existing application on the device.
189
205
# State:
190
- # AppManagement::APP_STATE_NOT_INSTALLED : The current application state cannot be determined/is unknown
191
- # AppManagement::APP_STATE_NOT_RUNNING : The application is not running
192
- # AppManagement::APP_STATE_RUNNING_IN_BACKGROUND_SUSPEND : The application is running in the background and is suspended
193
- # AppManagement::APP_STATE_RUNNING_IN_BACKGROUND : The application is running in the background and is not suspended
194
- # AppManagement::APP_STATE_RUNNING_IN_FOREGROUND : The application is running in the foreground
206
+ # AppState::NOT_INSTALLED : The current application state cannot be determined/is unknown
207
+ # AppState::NOT_RUNNING : The application is not running
208
+ # AppState::RUNNING_IN_BACKGROUND_SUSPENDED : The application is running in the background and is suspended
209
+ # AppState::RUNNING_IN_BACKGROUND : The application is running in the background and is not suspended
210
+ # AppState::RUNNING_IN_FOREGROUND : The application is running in the foreground
195
211
#
196
212
# For more details: https://developer.apple.com/documentation/xctest/xcuiapplicationstate
197
213
#
@@ -630,17 +646,45 @@ def create_bridge_command(method)
630
646
end
631
647
end
632
648
649
+ # rubocop:disable Metrics/ParameterLists,Metrics/PerceivedComplexity,Metrics/CyclomaticComplexity
633
650
def add_app_management
634
651
add_endpoint_method ( :install_app ) do
635
- def install_app ( path )
636
- execute :install_app , { } , appPath : path
652
+ def install_app ( path ,
653
+ replace : nil ,
654
+ timeout : nil ,
655
+ allow_test_packages : nil ,
656
+ use_sdcard : nil ,
657
+ grant_permissions : nil )
658
+ args = { appPath : path }
659
+
660
+ args [ :options ] = { } unless options? ( replace , timeout , allow_test_packages , use_sdcard , grant_permissions )
661
+
662
+ args [ :options ] [ :replace ] = replace unless replace . nil?
663
+ args [ :options ] [ :timeout ] = timeout unless timeout . nil?
664
+ args [ :options ] [ :allowTestPackages ] = allow_test_packages unless allow_test_packages . nil?
665
+ args [ :options ] [ :useSdcard ] = use_sdcard unless use_sdcard . nil?
666
+ args [ :options ] [ :grantPermissions ] = grant_permissions unless grant_permissions . nil?
667
+
668
+ execute :install_app , { } , args
669
+ end
670
+
671
+ private
672
+
673
+ def options? ( replace , timeout , allow_test_packages , use_sdcard , grant_permissions )
674
+ replace . nil? || timeout . nil? || allow_test_packages . nil? || use_sdcard . nil? || grant_permissions . nil?
637
675
end
638
676
end
639
677
640
678
add_endpoint_method ( :remove_app ) do
641
- def remove_app ( id )
679
+ def remove_app ( id , keep_data : nil , timeout : nil )
642
680
# required: [['appId'], ['bundleId']]
643
- execute :remove_app , { } , appId : id
681
+ args = { appId : id }
682
+
683
+ args [ :options ] = { } unless keep_data . nil? || timeout . nil?
684
+ args [ :options ] [ :keepData ] = keep_data unless keep_data . nil?
685
+ args [ :options ] [ :timeout ] = timeout unless timeout . nil?
686
+
687
+ execute :remove_app , { } , args
644
688
end
645
689
end
646
690
@@ -659,9 +703,15 @@ def activate_app(app_id)
659
703
end
660
704
661
705
add_endpoint_method ( :terminate_app ) do
662
- def terminate_app ( app_id )
706
+ def terminate_app ( app_id , timeout : nil )
663
707
# required: [['appId'], ['bundleId']]
664
- execute :terminate_app , { } , appId : app_id
708
+ #
709
+ args = { appId : app_id }
710
+
711
+ args [ :options ] = { } unless timeout . nil?
712
+ args [ :options ] [ :timeout ] = timeout unless timeout . nil?
713
+
714
+ execute :terminate_app , { } , args
665
715
end
666
716
end
667
717
@@ -672,22 +722,23 @@ def app_state(app_id)
672
722
673
723
case response
674
724
when 0
675
- Appium ::Core ::Device ::AppManagement :: APP_STATE_NOT_INSTALLED
725
+ Appium ::Core ::Device ::AppState :: NOT_INSTALLED
676
726
when 1
677
- Appium ::Core ::Device ::AppManagement :: APP_STATE_NOT_RUNNING
727
+ Appium ::Core ::Device ::AppState :: NOT_RUNNING
678
728
when 2
679
- Appium ::Core ::Device ::AppManagement :: APP_STATE_RUNNING_IN_BACKGROUND_SUSPEND
729
+ Appium ::Core ::Device ::AppState :: RUNNING_IN_BACKGROUND_SUSPENDED
680
730
when 3
681
- Appium ::Core ::Device ::AppManagement :: APP_STATE_RUNNING_IN_BACKGROUND
731
+ Appium ::Core ::Device ::AppState :: RUNNING_IN_BACKGROUND
682
732
when 4
683
- Appium ::Core ::Device ::AppManagement :: APP_STATE_RUNNING_IN_FOREGROUND
733
+ Appium ::Core ::Device ::AppState :: RUNNING_IN_FOREGROUND
684
734
else
685
735
Appium ::Logger . debug ( "Unexpected status in app_state: #{ response } " )
686
736
response
687
737
end
688
738
end
689
739
end
690
740
end
741
+ # rubocop:enable Metrics/ParameterLists,Metrics/PerceivedComplexity,Metrics/CyclomaticComplexity
691
742
692
743
def add_keyevent
693
744
# Only for Selendroid
0 commit comments