appium(7)-Automating mobile gestures
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的更多相关文章
- 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 ...
- (C#)Appium自动化测试之mobile:shell输入法
1.ADB执行Shell命令 a.如果电脑上已装Appium,那么需要在高级设置里勾选 Relaxed Security. 如图: b.cmd命令行启动appium appium --rela ...
- appium点击屏幕(手势)
在android测试过程中,会遇到要点击一下屏幕的需求. 在appium旧版本使用下面代码点击android屏幕,没有报错.Map tap = new HashMap(); tap.put(" ...
- appium架构分析
http://blog.sina.com.cn/s/blog_60c53af50102v3sb.html Appium - automation for mobile apps 一.Appium架 ...
- 【转载】使用appium遇到的坑
问题 1. error: Failed to start an Appium session, err was: Error: Requested a new session but one was ...
- Appium 工作原理
Appium - automation for mobile apps 一.Appium架构介绍 官网:www.appium.io 由SauceLab公司主持.并在Google的GATC2013会 ...
- Appium的一些问题的总结答案
问题 1. error: Failed to start an Appium session, err was: Error: Requested a new session but one ...
- C#中appium自动化执行移动命令mobile:shell用法
官网:https://appium.readthedocs.io/en/latest/en/commands/mobile-command/#android 1.执行ADB shell命令(需要设置服 ...
- appium for mobile web 之使用 ChromeDriver
之前研究了一段时间的appium for native app 相应的总结如下: appium测试环境搭建 :ht ...
随机推荐
- (5)Unity3d GUI
- FZU 2122 又见LKity【字符串/正难则反/KMP/把一个字符串中某个部分替换为另一个部分】
嗨!大家好,在TempleRun中大家都认识我了吧.我是又笨又穷的猫猫LKity.很高兴这次又与各位FZU的ACMer见面了.最近见到FZU的各位ACMer都在刻苦地集训,整天在日光浴中闲得发慌的我压 ...
- FMDB使用Cached Statement功能
FMDB使用Cached Statement功能 在FMDB中,Cached Statement功能是一种提高SQLite数据库访问的技术.在SQLite中,所有的SQL语句都会被编译,形成预处理 ...
- 分享Kali Linux 2017年第12周镜像文件
分享Kali Linux 2017年第12周镜像文件 Kali Linux官方于3月19日发布2017年的第12周镜像.这次维持了11个镜像文件的规模.默认的Gnome桌面的4个镜像,E17.KDE. ...
- mybatis ----SqlSessionManager
今天我们来看看这个类 有些写法还是很经典的 public class SqlSessionManager implements SqlSessionFactory, SqlSession { priv ...
- Eclipse安装Spring工具套件
前言: 安装spring工具套件是为了更快捷的使用spring,但是我觉得既然已经有了maven,工具套件其实不那么重要. 而且装好后我发觉没什么两样,只是新建bean文件时比较爽一点. 安装步骤: ...
- javascript --- 对象之间的继承
了解这一章之前,先把我们之前讲到的以构造函数创建对象为前提的继承抛到一边. 首先,我们先用一个var o = {}创建一个没有任何属性的空对象作为我们的‘画板’,然互在逐步向这个画板里添加属性,和方法 ...
- dubbo开发者指南
开发者指南 参与 流程 任务 版本管理 源码构建 框架设计 整体设计 模块分包 依赖关系 调用链 暴露服务时序 引用服务时序 领域模型 基本原则 扩展点加载 扩展点配置 扩展点自动包装 扩展点自动装配 ...
- python中a=a+2与a+=2的区别
1.a=a+2,表示一个新的对象,新的对象名字还是a,但是指向的内存地址已经变了 >>> a=2 >>> id(a) 140406287260016 >> ...
- oralce中相关的概念整理
[数据库名] 概念:就是一个数据库的标识,作用等同于我们的身份证的作用,假设一台机器上安装了多个数据库,那么每一个数据库都会有一个数据库名称相应,这些数据库名称在数据库被创建的时候,数据库名称也会被 ...