Appium - iOS 各种问题汇总

本文介绍了Appium在iOS设备上的滑动操作方法,包括swipe、flick及scroll的不同实现方式,并探讨了如何在iOS环境中隐藏软键盘、处理键盘遮挡问题。此外,还涉及了Xcode版本兼容性、sendKeys与setValue的区别等内容。

 Appium - iOS 各种问题汇总

作者: Max.Bai

时间: 2014/10



Appium - iOS 各种问题汇总


 1. Appium 滑动:

 swipe 有三种方式:
 第一种:swipe

JavascriptExecutor js = (JavascriptExecutor) driver;
WebElement  element = driver.findElementByXPath("xpath");
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,大于1 为coordinator。 小于1 为percent,比方0.5 代表50%

duration单位为秒, Android 能够设置0.1-60,iOS设置0.5-60

须要滑动特定的对象时须要指定的element。仅仅是在名目上滑动式就能够不指定element

另外一种: flick 差别swipe是没有duration

JavascriptExecutor js = (JavascriptExecutor) driver;
WebElement  element = driver.findElementByXPath("xpath");
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 scrollViewscroll方向滑动:

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

重要:方向和我们觉得的方向相反。比方要向下滑,就用Up,应为Up的意思是滑动到手机的顶部,左右也是一样,左滑就是Right

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


mac 版本号更换命令,改动成自己版本号相应的路径就好了:

sudo xcode-select -switch /Applications/Xcode-4.6.app/Contents/Developer/


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.youkuaiyun.com/wirelessqa/article/details/29188665


8. App or IPA ?

刚開始都想基于開始測试,发现怎么都是不行,无论App,和ipa格式的。如今我总结了一下分享给大家。

无论app的还是ipa的都要区分模拟器版本号和真机版本号

对于模拟器的,app的Appium不用解压,直接安装,ipa的Appium会解压找出app然后安装,问题来了,Appium用的解压工具是unzip。假设你的ipa里面包括中文的文件名称,预计要出问题了,这个是unzip的老问题,网上有方案。不在这里说了,最简单的就是使用app的包,不用解压。

对于真机的,眼下还没有測试,兴许有问题会更新。



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值