Appium - iOS 各类问题汇总

 Appium - iOS 各类问题汇总
java

做者: Max.Bainode

时间: 2014/10ios



Appium - iOS 各类问题汇总


 1. Appium 滑动:

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

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%xcode

duration单位为秒, Android 可以设置0.1-60,iOS设置0.5-60app

需要滑动特定的对象时需要指定的element。仅仅是在名目上滑动式就可以不指定elementless

另一种: flick 差异swipe是没有durationide

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的意思是滑动到手机的顶部,左右也是同样,左滑就是Rightthis

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.csdn.net/wirelessqa/article/details/29188665


8. App or IPA ?

刚開始都想基于開始測试,发现怎么都是不行,不管App,和ipa格式的。现在我总结了一下分享给你们。

不管app的仍是ipa的都要区分模拟器版本号和真机版本号

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

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

相关文章
相关标签/搜索