Skip to content

Commit 5eff035

Browse files
authored
add touch and hold (#581)
1 parent e736359 commit 5eff035

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

ios_tests/lib/ios/specs/ios/xcuitest_gestures.rb

+6
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@ def open_alert_custom
3636
double_tap(element: element)
3737
end
3838

39+
t 'touch_and_hold' do
40+
element = button('Tinted')
41+
touch_and_hold(element: element, duration: 4.0)
42+
touch_and_hold(x: 100, y: 100)
43+
end
44+
3945
t 'scroll' do
4046
scroll direction: 'down'
4147
text('Style Default').displayed?.must_equal true

lib/appium_lib/ios/xcuitest_gestures.rb

+19
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,25 @@ def double_tap(x: nil, y: nil, element: nil)
7171
execute_script 'mobile: doubleTap', args
7272
end
7373

74+
# @param x [float] Screen x long tap coordinate of type float. Mandatory parameter only if element is not set
75+
# @param y [float] Screen y long tap coordinate of type float. Mandatory parameter only if element is not set
76+
# @param duration [Float] The float duration of press action in seconds. Mandatory parameter
77+
# @option opts [Element] :element The internal element identifier (as hexadecimal hash string) to long tap on
78+
#
79+
# ```ruby
80+
# touch_and_hold x: 100, y: 100
81+
# touch_and_hold x: 100, y: 100, duration: 2.0
82+
# touch_and_hold element: find_element(:accessibility_id, "some item")
83+
# ```
84+
def touch_and_hold(x: nil, y: nil, element: nil, duration: 1.0)
85+
return 'require XCUITest(WDA)' unless automation_name_is_xcuitest?
86+
return 'Set x, y or element' if (x.nil? || y.nil?) && element.nil?
87+
88+
args = element.nil? ? { x: x, y: y } : { element: element.ref }
89+
args[:duration] = duration
90+
execute_script 'mobile: touchAndHold', args
91+
end
92+
7493
# @param [Element] :element Element to long tap on.
7594
#
7695
# ```ruby

0 commit comments

Comments
 (0)