Appium学习(Android)

写Android的Appium Tests 用到 java-client 方法列举:
1.发送keycode完成一些系统的操作

driver.pressKeyCode(4); //返回

2.测试Notification的时候

driver.openNotifications(); //不用去写下拉的动作

3.用UIAutomator获取元素 (AndroidDriver driver)

AndroidElement editElement = driver.findElementByAndroidUIAutomator("resourceId(\"io.appium.android.apis:id/edit\")");

或者

driver.findElement(MobileBy.AndroidUIAutomator("resourceId(\"io.appium.android.apis:id/edit\")"));

可以用UIAutomator的exists()判断元素是否存在
4.MobileBy有很多查找的方法

a (2).png

5.设备解锁,排除掉些会导致test fail的因素

@Test
public voidtestLock(){
if(driver.isLocked()){
driver.unlockDevice();
}
}

6.遇到ListView里面元素要定位时 native和webview一样 可以先拿到listview再定位

AndroidElement listView =driver.findElementByClassName("android.widget.ListView");
List list = listView.findElementsByClassName("android.view.View");
list.get(1).click();

7.往模拟器放文件 (我放的是图片)

File file=newFile(文件路径);
try{
driver.pushFile("/storage/emulated/0/Android/data/程序包名/cache/img/a.png",toByteArray(file));
}catch(IOException e) {
e.printStackTrace();
}
//文件转byte
public static byte[] toByteArray(File photo)throwsIOException {
FileInputStream fis =newFileInputStream(photo);
BufferedInputStream bis =newBufferedInputStream(fis);
ByteArrayOutputStream baos =newByteArrayOutputStream();
intc = bis.read();
while(c!=-1){
baos.write(c);
c=bis.read();
}
bis.close();
byte[] bytes= baos.toByteArray();
baos.close();
return bytes;
}

8.获取页面全部信息 会输出页面的xml

driver.getPageSource(); 

9.判断元素是否存在

if(driver.findElementsByClassName("android.widget.ListView").isEmpty()){   }

isDisplay()是判断元素visible的 元素不存在会test fail

java-client还有很多API 要用再查吧.....

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 173,898评论 25 709
  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 135,080评论 19 139
  • ¥开启¥ 【iAPP实现进入界面执行逐一显】 〖2017-08-25 15:22:14〗 《//首先开一个线程,因...
    小菜c阅读 6,637评论 0 17
  • 我从很小就认识小痞子了,他就住在我家对楼,在我房间一抬眼就能望见他。 人如其名,张痞,有点痞痞的,还记得以前他是个...
    书柒染阅读 595评论 0 2
  • 在我没有离开家乡的岁月都是跟姥爷一起生活的,姥爷的生日在腊月二十六,这一天是我的母系亲人们每年必定举行的年前大聚会...
    多多啰阅读 599评论 1 49