您现在的位置是:首页 > 文章详情

Appium滑动问题研究

日期:2017-07-02点击:360
一、Appium中,经常会遇到会遇到滑动操作,但往往用各种手势操作后还是滑动不了,今天主要讲下如何正确使用appium的手势操作。系统环境为最新的iOS 7.1+ Xcode 5.1
首先讲下滑动操作的几个基本方法。
1.swipe操作,主要用于缓慢拖动,代码示例
JavascriptExecutor js = (JavascriptExecutor) driver;
HashMap<String, Double> swipeObject = new HashMap<String, Double>();
swipeObject.put("startX", startX);
swipeObject.put("startY", startY);
swipeObject.put("endX", endX);
swipebject.put("endY", endY);
swipeObject.put("duration", duration);
swipeObject.put("element", Double.valueOf(((RemoteWebElement) element).getId()));
js.executeScript("mobile: swipe", swipeObject);
①X,Y可为coordinator,也可以是percent,duration单位为秒
②可以指定的element,也可以不指定
③appium mac端有swipe的按钮可以试下
2.flick操作,类似swipe,但没有duration,用于快速滑动,如ViewController的切换,代码示例
JavascriptExecutor js = (JavascriptExecutor) driver;
HashMap<String, Double> flickObject = new HashMap<String, Double>();
flickObject.put("startX", 0.8);
flickObject.put("startY", 0.5);
flickObject.put("endX", 0.2);
flickObject.put("endY", 0.5);
flickObject.put("element", Double.valueOf(((RemoteWebElement) element).getId()));
js.executeScript("mobile: flick", flickObject););
3.scroll操作,专为iOS 7.x而生,官方的解释如下
An unfortunate bug exists in the iOS 7.x Simulator where ScrollViews 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 a ScrollView, namely, scroll it!
简而言之,iOS 7的系统ScrollView无法识别手势操作,使用scroll方法可完美替代,代码见例子
二、接下来以三个不同app的引导图为例,分别为看游戏,云阅读和云音乐,演示下不同方法实现的滑动操作
1.看游戏,引导图以ScrollView引导,只需要使用srcoll方法即可
JavascriptExecutor js = (JavascriptExecutor) driver;
HashMap<String, String> scrollObject = new HashMap<String, String>();
scrollObject.put("direction", "right");
js.executeScript("mobile: scroll", scrollObject
2.云音乐,引导图以ScrollView引导,分别为4张image
如上所示,如果使用swipe或flick方法是不可以滑动引导图的,而用Scroll的方向模式也不行,这里采用如下方法
JavascriptExecutor js = (JavascriptExecutor) driver;
WebElement  element = driver.findElementByXPath("4张image的xpath路径");
HashMap<String, String> scrollObject = new HashMap<String, String>();
scrollObject.put("element", ((RemoteWebElement) element).getId());
js.executeScript("mobile: scroll", scrollObject);
3.云阅读,云阅读的引导图并不是存在于ScrollView中,而是专门有一个UIAElement存放,那就只需要用swipe拖动这个UIAElement就好了,如图所示。
代码见swipe方法。


最新内容请见作者的GitHub页:http://qaseven.github.io/
原文链接:https://yq.aliyun.com/articles/132155
关注公众号

低调大师中文资讯倾力打造互联网数据资讯、行业资源、电子商务、移动互联网、网络营销平台。

持续更新报道IT业界、互联网、市场资讯、驱动更新,是最及时权威的产业资讯及硬件资讯报道平台。

转载内容版权归作者及来源网站所有,本站原创内容转载请注明来源。

文章评论

共有0条评论来说两句吧...

文章二维码

扫描即可查看该文章

点击排行

推荐阅读

最新文章