While the Selenium WebDriver spec has support for certain kinds of mobile interaction, its parameters are not always easily mappable to the functionality that the underlying device automation (like UIAutomation in the case of iOS) provides. To that end, Appium implements the new TouchAction / MultiAction API defined in the newest version of the spec (https://w3c.github.io/webdriver/webdriver-spec.html#multiactions-1). Note that this is different from the earlier version of the TouchAction API in the original JSON Wire Protocol.//尽管Selenium Webdriver提供了一些对移动端交互的支持,但是不好用。所以,Appium提供了TouchAction/MultiAction接口,来解决这个问题。

These APIs allow you to build up arbitrary gestures with multiple actuators. Please see the Appium client docs for your language in order to find examples of using this API.

  

TouchAction

TouchAction objects contain a chain of events.

In all the appium client libraries, touch objects are created and are given a chain of events.

The available events from the spec are: * press * release * moveTo * tap * wait * longPress * cancel * perform//TouchAction是由一系列事件组成的。

Here’s an example of creating an action in pseudocode:

TouchAction().press(el0).moveTo(el1).release()

The above simulates a user pressing down on an element, sliding their finger to another position, 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 relative 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(100,100) // Increase X & Y by 100 each, ending up at 200,200//moveTo的坐标参数是个相对值。

The appium client libraries have different ways of implementing this, for example: you can pass in coordinates or an element to a `moveTo` event. Passing both coordinates _and_ an element will treat the coordinates as relative to the element's position, rather than relative to the current position. Calling the `perform` event sends the entire sequence of events to appium, and the touch gesture is run on your device. Appium clients also allow one to directly execute a TouchAction through the driver object, rather than calling the `perform` event on the TouchAction object. In pseudocode, both of the following are equivalent:TouchAction().tap(el).perform() driver.perform(TouchAction().tap(el))

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://MultiTouch有add和perform两个方法。

action0 = TouchAction().tap(el) action1 = TouchAction().tap(el) MultiAction().add(action0).add(action1).perform()

Bugs and Workarounds

An unfortunate bug exists in the iOS 7.0 - 8.x Simulators where ScrollViews, CollectionViews, and TableViews don't recognize gestures initiated by UIAutomation (which Appium uses under the hood for iOS). To work around this, we have provided access to a different function, `scroll`, which in many cases allows you to do what you wanted to do with one of these views, namely, scroll it!//在iOS7.0~8.x系统的模拟器中,ScrollViews、CollectionViews、TableViews无效。为解决这个问题,需要使用scroll。

**Scrolling** To allow access to this special feature, we override the `execute` or `executeScript` methods in the driver, and prefix the command with `mobile: `. See examples below: To scroll, pass direction in which you intend to scroll as parameter.


 // javascript
driver.execute("mobile: scroll", [{direction: 'down'}])

 
 # python
driver.execute_script("mobile: scroll", {"direction": "down"})

Sample to scroll using direction and element.

 # python
driver.execute_script("mobile: scroll", {"direction": "down", element: element.getAttribute("id")})
 // java
JavascriptExecutor js = (JavascriptExecutor) driver;
HashMap<String, String> scrollObject = new HashMap<String, String>();
scrollObject.put("direction", "down");
js.executeScript("mobile: scroll", scrollObject);

Sample to scroll using direction and element.

 // 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);

Automating Sliders

iOS

 // java
// slider values can be string representations of numbers between 0 and 1
// e.g., "0.1" is 10%, "1.0" is 100%
WebElement slider = driver.findElement(By.xpath("//window[1]/slider[1]"));
slider.sendKeys("0.1");

Android

The best way to interact with the slider on Android is with TouchActions.

appium(7)-Automating mobile gestures的更多相关文章

  1. appium(4)-Automating mobile web apps

    Automating mobile web apps If you’re interested in automating your web app in Mobile Safari on iOS o ...

  2. (C#)Appium自动化测试之mobile:shell输入法

    1.ADB执行Shell命令 a.如果电脑上已装Appium,那么需要在高级设置里勾选 Relaxed Security. 如图:     b.cmd命令行启动appium appium --rela ...

  3. appium点击屏幕(手势)

    在android测试过程中,会遇到要点击一下屏幕的需求. 在appium旧版本使用下面代码点击android屏幕,没有报错.Map tap = new HashMap(); tap.put(" ...

  4. appium架构分析

    http://blog.sina.com.cn/s/blog_60c53af50102v3sb.html Appium - automation for mobile apps   一.Appium架 ...

  5. 【转载】使用appium遇到的坑

    问题 1. error: Failed to start an Appium session, err was: Error: Requested a new session but one was ...

  6. Appium 工作原理

    Appium - automation for mobile apps   一.Appium架构介绍 官网:www.appium.io 由SauceLab公司主持.并在Google的GATC2013会 ...

  7. Appium的一些问题的总结答案

        问题 1. error: Failed to start an Appium session, err was: Error: Requested a new session but one ...

  8. C#中appium自动化执行移动命令mobile:shell用法

    官网:https://appium.readthedocs.io/en/latest/en/commands/mobile-command/#android 1.执行ADB shell命令(需要设置服 ...

  9. appium for mobile web 之使用 ChromeDriver

    之前研究了一段时间的appium for native app 相应的总结如下:                                            appium测试环境搭建 :ht ...

随机推荐

  1. Toast问题记录:This Toast was not created with Toast.makeText()

    最近使用自己封装的Toast时,遇到一个问题 java.lang.RuntimeException: This Toast was not created with Toast.makeText() ...

  2. SQL盲注工具BBQSQL

    SQL盲注工具BBQSQL   SQL注入是将SQL命令插入到表单.域名或者页面请求的内容中.在进行注入的时候,渗透测试人员可以根据网站反馈的信息,判断注入操作的结果,以决定后续操作.如果网站不反馈具 ...

  3. IIS下安装memcached管理工具—MemAdmin

    1.先看这篇文章 http://www.cnblogs.com/joylee/archive/2013/01/07/memadmin.html . 2.在IIS下安装的php-cgi.exe程序版本为 ...

  4. 使用Crashlytics来保存应用崩溃信息

    使用Crashlytics来保存应用崩溃信息 本文首发于InfoQ,版权归InfoQ所有,转载请保留原文链接. 简介 Crashlytic 成立于2011年,是专门为移动应用开者发提供的保存和分析应用 ...

  5. C#网络编程系列文章(一)之Socket实现异步TCPserver

    原创性声明 本文作者:小竹zz 本文地址http://blog.csdn.net/zhujunxxxxx/article/details/44258719 转载请注明出处 文章系列文件夹 C#网络编程 ...

  6. 如何在Linux中使用sFTP上传或下载文件与文件夹

    如何在Linux中使用sFTP上传或下载文件与文件夹 sFTP(安全文件传输程序)是一种安全的交互式文件传输程序,其工作方式与 FTP(文件传输协议)类似. 然而,sFTP 比 FTP 更安全;它通过 ...

  7. 兔子--html,js,php,ASP,ASP.NET,JSP的关系

    html是超文本链接语言.是静态的.显示在client.仅仅用HTML做出来的网页是静态网页.没不论什么交互功能. JS是一种基于对象和事件驱动的脚本语言,执行在client.是一种比較简单的编程语言 ...

  8. Selenium系列之--07 操作远程浏览器

    Selenium远程控制浏览,可以通过如下两种方式实现,本质上都是Selenium Grid a.  客户机启Selenium Standalone Server 作为远程服务,服务端通过调用Remo ...

  9. quick-cocos2d-x教程12:实现文本和password输入界面

    用户输入账号和password输入是常见工能,如今用editbox来实现username和password输入.可是这个商业项目上常见功能,网上却没有找到教程.我就一步一步的实现.代码例如以下: fu ...

  10. Java反射及其在Android中的应用学习总结

    一. Java反射机制 Reflection 是Java被视为动态(或准动态)语言的一个关键性质.这个机制同意程序在执行时透过Reflection APIs取得不论什么一个已知名称的class的内部信 ...