Skip to content

Commit bc3b8df

Browse files
authored
add pressure option (appium#322)
* add pressure option * add a test, tweak comment and the method * fix typo
1 parent de17fcd commit bc3b8df

2 files changed

Lines changed: 20 additions & 3 deletions

File tree

‎appium/webdriver/common/touch_action.py‎

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,17 @@ def tap(self, element=None, x=None, y=None, count=1):
4949

5050
return self
5151

52-
def press(self, el=None, x=None, y=None):
52+
def press(self, el=None, x=None, y=None, pressure=None):
5353
"""Begin a chain with a press down action at a particular element or point
54+
55+
:Args:
56+
- el - (optional) the element to press
57+
- x - (optional) x coordiate to press. If y is used, x must also be set
58+
- y - (optional) y coordiate to press. If x is used, y must also be set
59+
- pressure - (optional) [iOS Only] press as force touch. Read the description of `force` property on Apple's UITouch class
60+
(https://developer.apple.com/documentation/uikit/uitouch?language=objc) for more details on possible value ranges.
5461
"""
55-
self._add_action('press', self._get_opts(el, x, y))
62+
self._add_action('press', self._get_opts(el, x, y, pressure=pressure))
5663

5764
return self
5865

@@ -114,7 +121,7 @@ def _add_action(self, action, options):
114121
}
115122
self._actions.append(gesture)
116123

117-
def _get_opts(self, element, x, y, duration=None):
124+
def _get_opts(self, element, x, y, duration=None, pressure=None):
118125
opts = {}
119126
if element is not None:
120127
opts['element'] = element.id
@@ -127,4 +134,7 @@ def _get_opts(self, element, x, y, duration=None):
127134
if duration is not None:
128135
opts['duration'] = duration
129136

137+
if pressure is not None:
138+
opts['pressure'] = pressure
139+
130140
return opts

‎test/unit/webdriver/touch_action_test.py‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,13 @@ def test_press_json(self, touch_action):
4444
touch_action.press(ElementStub(1))
4545
assert json == touch_action.json_wire_gestures
4646

47+
def test_press_pressure_json(self, touch_action):
48+
json = [
49+
{'action': 'press', 'options': {'element': 1, 'pressure': 1.0}}
50+
]
51+
touch_action.press(ElementStub(1), pressure=1.0)
52+
assert json == touch_action.json_wire_gestures
53+
4754
def test_press_x_y_json(self, touch_action):
4855
json = [
4956
{'action': 'press', 'options': {'element': 1, 'x': 3, 'y': 4}}

0 commit comments

Comments
 (0)