@@ -64,10 +64,14 @@ module Device
64
64
# @!method hide_keyboard
65
65
# Hide the onscreen keyboard
66
66
# @param [String] close_key The name of the key which closes the keyboard.
67
- # Defaults to 'Done'.
67
+ # Defaults to 'Done' for iOS(except for XCUITest).
68
+ # @param [Symbol] strategy The symbol of the strategy which closes the keyboard.
69
+ # XCUITest ignore this argument.
70
+ # Default for iOS is `:pressKey`. Default for Android is `:tapOutside`.
68
71
# ```ruby
69
72
# hide_keyboard # Close a keyboard with the 'Done' button
70
73
# hide_keyboard('Finished') # Close a keyboard with the 'Finished' button
74
+ # hide_keyboard(nil, :tapOutside) # Close a keyboard with tapping out side of keyboard
71
75
# ```
72
76
73
77
# @!method press_keycode
@@ -273,20 +277,20 @@ def set_context(context = null)
273
277
end
274
278
275
279
add_endpoint_method ( :hide_keyboard ) do
276
- def hide_keyboard ( close_key = nil )
277
- # Android can only tapOutside.
278
- if $driver. device_is_android?
279
- return execute :hide_keyboard , { } , strategy : :tapOutside
280
- end
281
-
282
- close_key ||= 'Done' # default to Done key.
283
- if $driver. automation_name_is_xcuitest?
284
- # strategy is not implemented in the following
285
- # https://github.com/appium/appium-xcuitest-driver/blob/v2.2.0/lib/commands/general.js#L51
286
- execute :hide_keyboard , { } , strategy : :grouped , key : close_key
280
+ def hide_keyboard ( close_key = nil , strategy = nil )
281
+ option = { }
282
+
283
+ if $driver. device_is_android? # Android can only tapOutside.
284
+ option [ :key ] = close_key if close_key
285
+ option [ :strategy ] = strategy || :tapOutside # default to pressKey
286
+ elsif $driver. automation_name_is_xcuitest?
287
+ option [ :key ] = close_key if close_key
288
+ option [ :strategy ] = strategy if strategy
287
289
else
288
- $driver. hide_ios_keyboard close_key
290
+ option [ :key ] = close_key || 'Done' # default to Done key.
291
+ option [ :strategy ] = strategy || :pressKey # default to pressKey
289
292
end
293
+ execute :hide_keyboard , { } , option
290
294
end
291
295
end
292
296
0 commit comments