touchAction

The Touch Action API provides the basis of all gestures that can be automated in Appium. It is currently only available to native apps and can not be used to interact with webapps. At its core is the ability to chain together ad hoc individual actions, which will then be applied to an element in the application on the device. The basic actions that can be used are:

  • press (pass selector or (x,y) or both)
  • longPress (pass selector or (x,y) or both)
  • tap (pass selector or (x,y) or both)
  • moveTo (pass selector or (x,y) or both)
  • wait (pass ms (as milliseconds))
  • release (no arguments)

If you use the touchAction command with a selector you don’t need to pass the selector to each action. It will be propagated by the internally (if no x or y parameters are given).

Usage

1
browser.touchAction(selector,action);

Parameters

Param Type Details
selector String selector to execute the touchAction on
action String action to execute

Example

touchAction.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
it('should do a touch gesture', function () {
var screen = $('//UITextbox');

// simple touch action on element
screen.touchAction('tap');
// same as
browser.touchAction('//UITextbox', 'tap')

// simple touch action using x y variables
browser.touchAction({
action: 'tap', x: 300, y:200
})

// simple touch action using selector and x y variables
// tap location is 30px right and 20px down relative from the center of the element
browser.touchAction({
action: 'tap', x: 30, y:20, selector: '//UIAApplication[1]/UIAElement[2]'
})

// multi action on an element (drag&drop)
screen.touchAction([
'press',
{ action: 'moveTo', x: 200, y: 0 },
'release'
])
// same as
browser.touchAction('//UITextbox', [
'press',
{ action: 'moveTo', x: 200, y: 0},
'release'
])

// drag&drop to element
screen.touchAction([
'press',
{ action: 'moveTo', selector: '//UIAApplication[1]/UIAElement[2]' },
'release'
]))
});
multiTouchAction.js
1
2
3
4
5
6
7
it('should do a multitouch gesture', function () {
// drag&drop with two fingers 200px down
browser.touchAction([
[{action: 'press', x: 10, y: 10}, { action: 'moveTo', x: 0, y: 200 }, 'release'],
[{action: 'press', x: 100, y: 10}, { action: 'moveTo', x: 0, y: 200 }, 'release']]
])
})

Support

Support for android Support for ios

Uses