Automation of mobile gestures

Source: Internet
Author: User

# # Automation of Mobile gestures

Although the selenium Webdriver specification supports several ways to interact with a cell phone, its parameters do not simply map to the automation functions used by the underlying device (like the uiautomation on iOS). To this end, Appium defines a new touch operation/Multitouch API in the latest version of the specification
([Https://dvcs.w3.org/hg/webdriver/raw-file/tip/webdriver-spec.html#multiactions-1] (https://dvcs.w3.org/hg/ WEBDRIVER/RAW-FILE/TIP/WEBDRIVER-SPEC.HTML#MULTIACTIONS-1)).
Note that this is different from the touch Operation API used in earlier versions of the original JSON wire Protocol.

These APIs enable you to use multiple drivers to create arbitrary gestures. Refer to the Appium client documentation for the corresponding language to find examples of using these APIs.


Overview of # # # Touch Operations/Multitouch API

# # # Touch operation (touchaction)

The *touchaction* object contains a series of events.

In all Appium client libraries, touch objects Create and give a series of events.

The available events in the specification are:
* Short push (press)
* Released (release)
* Move to (MoveTo)
* Click (TAP)
* Waiting (Wait)
* Long Press (longpress)
* Cancellation (Cancel)
* Execution (perform)

Here is an example of creating an action with pseudo-code:

"' Center
Touchaction (). Press (EL0). MoveTo (EL1). Release ()
```

The above simulated user presses an element, slides his finger to another position, and then releases its finger from the screen.

These events are executed sequentially by Appium. You can add a ' wait ' event to control the time of the corresponding gesture.

The Appium client library has different ways to implement the above example, such as: you can pass a coordinate value or an element to the ' MoveTo ' event. Passing coordinates and elements at the same time corresponds to the coordinates and elements, but this is not absolute.


Call the ' perform ' event to send the entire sequence of events to Appium, allowing the touch gesture to run on the device.

The Appium client also allows people to perform touch operations directly from the driver object, rather than invoking the ' perform ' event of the touch manipulation object.


In pseudo-code, the following two are equivalent:

"' Center
Touchaction (). Tap (EL). Perform ()

Driver.perform (Touchaction (). Tap (EL))
```

# # # Multi-Touch (MultiTouch)

The *multitouch* object is a collection of touch operations.

Multitouch gestures only have two methods, add (' Add ') and execute (' perform ').

' Add ' is used to add different touch actions to a multi-touch.

When ' perform ' is called, all touch events that are added to the multi-touch will be sent to Appium and executed as if they were happening at the same time. Appium executes the first event in touch events, then the second one, and so on.


Sample code with two finger clicks:

"' Center
Action0 = Touchaction (). Tap (EL)
Action1 = Touchaction (). Tap (EL)
Multiaction (). Add (Action0). Add (Action1). Perform ()
```

# # # Defects and Solutions

Unfortunately there is a flaw in iOS 7.x simulator, Scrollviews does not recognize gestures created by uiautomation (Appium using UIAutomation on iOS). In order to implement this function, we have provided new functions, ' scroll ', which in most cases allows you to achieve the same functions as ScrollView!

* * Scrolling * *


To use this special feature, we rewrote the ' execute ' in driver and
' Executescript ' method. You can use scrolling by prefixing the command with ' Mobile: '.
See the following example:

* **wd.js:**

"' JavaScript
Javascript
Slide the View down
Driver.execute ("Mobile:scroll", [{direction: ' down '}])
Continue testing
```

* **java:**

"' Java
Java
Javascriptexecutor js = (javascriptexecutor) driver;
hashmap<string, string> scrollobject = new hashmap<string, string> ();
Scrollobject.put ("direction", "down");
Scrollobject.put ("Element", (remotewebelement) Element). GetId ());
Js.executescript ("Mobile:scroll", scrollobject);
```

* * Automatic Slider Automation * *


**ios**

* **java**

"' Java
Java
Slide values are represented as strings using numbers between 0 and 1
For example, "0.1" stands for 10%, "1.0" for 100%
Webelement slider = driver.findelement (By.xpath ("//window[1]/slider[1]");
Slider.sendkeys ("0.1");
```

**android**

The best way to interact with the sliders on Android is with touch operation (touchactions).

Automation of mobile gestures

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.