- Jun 20, 2018
- admin
- 0
An Overview of the TouchAction / MultiAction API
What is Touch Action?
TouchAction objects contain a chain of events.
In all the appium client libraries, touch objects are created and are given a chain of events.
What are Available Events?
The available events from the spec are:
* press
* release
* moveTo
* tap
* wait
* longPress
* cancel
* perform
Here’s an example of creating an action in pseudocode:
TouchAction().press(element1).moveTo(element2).release()
The above code simulates a user pressing down on an element (ex: element1), sliding their finger to another position (ex: element2), and removing their finger from the screen.
Appium performs the events in sequence. You can add a wait event to control the timing of the gesture.
moveTo coordinates are now absolute to the current position. For example, dragging from 100,100 to 200,200 can be achieved by:
.press(100,100) // Start at 100,100
.moveTo(200,200) // Passing absolute values of 200,200 ending up at 200,200
TouchAction().press(100,100).moveTo(200,200)
Calling the perform event sends the entire sequence of events to appium, and the touch gesture is run on your device.
TouchAction().press(100,100).moveTo(200,200).perform()
MultiTouch
MultiTouch objects are collections of TouchActions.
MultiTouch gestures only have two methods, add, and perform.
add is used to add another TouchAction to this MultiTouch.
When perform is called, all the TouchActions which were added to the MultiTouch are sent to appium and performed as if they happened at the same time.
Appium first performs the first event of all TouchActions together, then the second, etc.
Pseudocode example of tapping with two fingers:
action0 = TouchAction().tap(el)
action1 = TouchAction().tap(el)
MultiAction().add(action0).add(action1).perform()