天天看點

Appium滑動問題研究

  首先講下滑動操作的幾個基本方法。

  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的切換,代碼示例

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

Appium滑動問題研究

<a href="http://www.51testing.com/batch.download.php?aid=46579" target="_blank"></a>

Appium滑動問題研究

  如上所示,如果使用swipe或flick方法是不可以滑動引導圖的,而用scroll的方向模式也不行,這裡采用如下方法

  webelement  element = driver.findelementbyxpath("4張image的xpath路徑");

  scrollobject.put("element", ((remotewebelement) element).getid());

  js.executescript("mobile: scroll", scrollobject);

  3.雲閱讀,雲閱讀的引導圖并不是存在于scrollview中,而是專門有一個uiaelement存放,那就隻需要用swipe拖動這個uiaelement就好了,如圖所示。

Appium滑動問題研究

  代碼見swipe方法。

最新内容請見作者的github頁:http://qaseven.github.io/

繼續閱讀