IOS滑动操作

Appium - iOS 各种问题汇总

时间: 2014/10



Appium - iOS 各种问题汇总

java-client从4.1.2升级到5.0.2,API中找不到swipe方法,应该是高版本的java-client舍弃了swipe

 1. Appium 滑动:

 swipe 有三种方式:
 第一种: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("direction", "left");

swipeObject.put("element", Double.valueOf(((RemoteWebElement) element).getId()));
js.executeScript("mobile: swipe", swipeObject);


X,Y可为coordinator,也可以是percent,duration单位为秒, Android 可以设置0.1-60,iOS设置0.5-60

可以指定的element,也可以不指定

JavascriptExecutor js = (JavascriptExecutor) driver;

HashMap<String, String> swipeObject = new HashMap<String, String>();

swipeObject.put("startX", "80%");

swipeObject.put("startY", "174");

//swipeObject.put("endX", "56");

swipeObject.put("endX", "50%");

swipeObject.put("endY", "0");

swipeObject.put("duration", "1");

swipeObject.put("direction", "left");

swipeObject.put("element", ((RemoteWebElement)el).getId()+"");

js.executeScript("mobile: swipe", swipeObject);

第二种: flick 区别swipe是没有duration
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););
第三种: scroll only for iOS scrollView
scroll方向滑动:
JavascriptExecutor js = (JavascriptExecutor) _driver;
HashMap<String, String> scrollObject = new HashMap<String, String>();
scrollObject.put("direction", sDrection);        
js.executeScript("mobile: scroll", scrollObject);

方向接受参数:Right, Left, Up, Down
scroll对象滑动:
JavascriptExecutor js = (JavascriptExecutor) driver;
WebElement  element = driver.findElementByXPath("scrollview中元素的xpath");
HashMap<String, String> scrollObject = new HashMap<String, String>();
scrollObject.put("element", ((RemoteWebElement) element).getId());
js.executeScript("mobile: scroll", scrollObject);


2. 隐藏键盘hideKeyboard()

为了避免输入框输入内容后键盘遮挡控件,需要对键盘隐藏
Android可以设置如下cap来输入中文,同时能达到隐藏键盘的效果,但是这个设置只能针对Android。
capabilities.setCapability("unicodeKeyboard", true);
capabilities.setCapability("resetKeyboard", true);
iOS 就必须掉用方法hideKeyboard()
默认是点非输入框的地方键盘自动隐藏,如果不生效(开发没有做这个效果),就需要使用其他方法,比如:通过点击“Done”来隐藏键盘
hideKeyboard(HideKeyboardStrategy.PRESS_KEY, "Done")

3. Xcode 版本

Appium 1.2.* 对应Xcode5.0
Appium 1.3  对应Xcode6.0
可能出现错误:
Error: Could not find Automation.tracetemplate
Error: Could not find ios simulator binary at /application/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator

4. Sendkeys vs setValue

Sendkeys iOS无法输入
可以试用setvalue代替
((MobileElement)_driver.findElement(by)).setValue(sText);

5. isAppInstalled/removeApp/installApp 

isAppInstalled这个方法在Android里面可以使用(模拟器和真机都试过)
但是在iOS里面使用模拟器返回值总是false,没有错误信息,后来查看源代码发现
cb(new Error("You can not call isInstalled for the iOS simulator!"));
同样removeApp/installApp 都是

6. App path 设置

官网说可以用remote URL设置cap 的app
官网说明如下:
app    The absolute local path or remote http URL to an .ipa or .apk file, or a .zip containing one of these. Appium will attempt to install this app binary on the appropriate device first. e.g.: /abs/path/to/my.apk or http://myapp.com/app.ipa
我为了方便集中管理安装程序所以使用了http://sssss/x.zip
坑爹的问题来了,Android根本就不支持,报错找不到提供的app
iOS 还好,可以安装,但是测试中发现好多控件和放在本地完全不是一个效果。。。
所以还是老老实实的使用本地设置吧
ps: 貌似1.3解决了Android http 的问题,还没有验证

7. sudo安装Appium后无法启动

sudo npm install -g appium后果
Appium will not work if used or installed with sudo
网上有高人解决了这个问题
过程如下:
步骤1. 改变node的所有者

cd /usr/local/lib
sudo chown -R bixiaopeng node_modules

步骤2. 卸载appium

npm uninstall appium -g

步骤3. 重新安装appium

npm install -g appium
步骤4. 启动

appium
原链接:http://blog.csdn.net/wirelessqa/article/details/29188665

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值