转载:http://www.cnblogs.com/dokaygang128/p/3517674.html

一、一些注意事项:

1.做自动化测试时注意如果是真机话首先要设置不锁屏。

2.自动化测试过程中如果程序后台或崩溃了。脚本运行将会暂停,直到程序再次回到前台。

3.必须明确指定关闭自动测试,测试完成或中断都不会自动关闭测试。

4.测试也是根据视图树的元素位置获取元素进行测试,根视图元素是UIATarget。

二、部分功能说明:

1.获取当前程序(在激活状态):

UIATarget.localTarget().frontMostApp();

2.获取目标程序的主Window:

UIATarget.localTarget().frontMostApp().mainWindow();

3.获取一个cell中的文本元素:

UIATarget.localTarget().frontMostApp().mainWindow().tableViews()[0].cells()[0].elements()["Chocolate Cake"];

4.触发一个导航栏中“Add”按钮点击:

UIATarget.localTarget().frontMostApp().navigationBar().buttons()["Add"].tap();

5.触发点击屏幕上的某个位置:

UIATarget.localTarget().doubleTap({x:100, y:200});

UIATarget.localTarget().twoFingerTap({x:100, y:200});

6.获取tabBar并点击:

appWindow.tabBar().buttons()["Unit Conversion"].tap();

7.放大:

UIATarget.localTarget().pinchOpenFromToForDuration({x:20, y:200}, {x:300, y:200}, 2);

缩小(后面是个时间参数,表示持续时间):

UIATarget.localTarget().pinchCloseFromToForDuration({x:20, y:200}, {x:300, y:200}, 2);

8.拖拽和快速滑动:

UIATarget.localTarget().dragFromToForDuration({x:160, y:200}, {x:160, y:400}, 1);

UIATarget.localTarget().flickFromTo({x:160, y:200}, {x:160, y:400});

9.为文本框输入内容:

var recipeName = "Unusually Long Name for a Recipe";
UIATarget.localTarget().frontMostApp().mainWindow().textFields()[0].setValue(recipeName);

10.在tabBar中导航

var tabBar = UIATarget.localTarget().frontMostApp().mainWindow().tabBar();

 var selectedTabName = tabBar.selectedButton().name();

 if (selectedTabName != "Unit Conversion") { 

tabBar.buttons()["Unit Conversion"].tap();

}

11.tableview滚动到一个name以“Turtle Pie.”开头的元素:

根据name模糊查询控件,firstWithPredicate(“name beginswith ‘xxx’”),根据name完全匹配,firstWithName(“xxxx”),/根据key值匹配,firstWithValueForKey(value,key):

UIATarget.localTarget().frontMostApp().mainWindow().tableViews()[0].scrollToElementWithPredicate("name beginswith ‘Turtle Pie’");

不使用预测功能:scrollToElementWithName和scrollToElementWithValueForKey

12.增加时间控制:

//压栈时间片:

UIATarget.localTarget().pushTimeout(2);

//接着执行脚本任务;

//时间片出栈

UIATarget.localTarget().popTimeout();

还有一种方式,采用delay方式:

UIATarget.localTarget().delay(2);

两种方式的区别是,在时间片内,第一种方法会不断尝试去执行压栈和出栈间的脚本任务,一旦可以执行就执行,不一定在时间片后才执行,而第二种方式是在时间片到后才执行脚本任务。

13.按钮点击:

UIATarget.localTarget().frontMostApp().mainWindow().buttons()["xxxxx"].tap();

14截屏功能,事实证明模拟器是能使用截屏功能的:

UIATarget.localTarget().captureScreenWithName("SS001-2_AddedIngredient");

15.验证结果:

var cell = UIATarget.localTarget().frontMostApp().mainWindow().tableViews()[0].cells().firstWithPredicate("name beginswith ‘Tarte’");

if (cell.isValid()) {

UIALogger.logPass(testName);

}

else {

UIALogger.logFail(testName);

}

16.处理弹框,只需指定UIATarget.onAlert:

UIATarget.onAlert = function onAlert(alert) {

 var title = alert.name();

UIALogger.logWarning("Alert with title '" + title + "' encountered.");

if (title == "The Alert We Expected") {

alert.buttons()["Continue"].tap();

return true; //alert handled, so bypass the default handler

}

// return false to use the default handler

 return false;

}

返回FALSE代表点击取消,TRUE代表确定。

17.模拟后台一段时间:

UIATarget.localTarget().deactivateAppForDuration(10);

手机方向旋转:

UIATarget.localTarget().setDeviceOrientation(UIA_DEVICE_ORIENTATION_PORTRAIT);

18.拖动


window.tableViews()[0].scrollDown();


window.tableViews()[0].scrollUp();


window.tableViews()[0].scrollLeft();


window.tableViews()[0].scrollRight();

19.打印当前屏幕所有空间信息

UIATarget.localTarget().logElementTree();

20.记录日志


UIALogger.logStart(“start”);


UIALogger.logPass(“pass”);


UIALogger.logWarning(“warning”);


UIALogger.logFail(“fail”);


UIALogger.logMessage(“message”);


UIALogger.logError(“error”);


UIALogger.logDebug(“debug”);


UIALogger.logIssue(“issue”);

21.九宫格搜索输入框


UIATarget.localTarget().frontMostApp().mainWindow().searchBars()[0]

22.模拟键盘操作,


UIATarget.localTarget().frontMostApp().keyboard().typeString(“aaa\n”);\n=回车

23.输入框输入,


UIATarget.localTarget().frontMostApp().mainWindow().tableViews()["Empty list"].cells()["用户名:"].textFields()[0].setValue(“abcd”);

24.获取对象数组长度,

UIATarget.localTarget().frontMostApp().mainWindow().buttons().length;

25.获取文本字符串,

UIATarget.localTarget().frontMostApp().mainWindow().scrollViews()[0].staticTexts()[0].value();

26.打印当前元素的视图树:

.logElementTree();

27.筛选框滚动,

UIATarget.localTarget().frontMostApp().mainWindow().pickers()[0].wheels()[0].dragInsideWithOptions({startOffset:{x:0.38, y:0.66}, endOffset:{x:0.38, y:0.12}, duration:1.6});

ios UI自动化测试的更多相关文章

  1. ios UI自动化测试学习笔记

    一.一些注意事项: 1.做自动化测试时注意如果是真机话首先要设置不锁屏. 2.自动化测试过程中如果程序后台或崩溃了.脚本运行将会暂停,直到程序再次回到前台. 3.必须明确指定关闭自动测试,测试完成或中 ...

  2. <自动化测试方案_8>第八章、手机端UI自动化测试

    第八章.手机端UI自动化测试 (一)APP测试分类 1,原生APP:Native页面是使用原生系统内核的,相当于直接在系统上操作 2,H5APP:先调用系统的浏览器内核,相当于是在网页中进行操作,较原 ...

  3. 【转】 UI自动化测试的关注点

    我发现了,大家极度关心自动化测试,尤其是UI自动化测试,虽然现在作为专项测试,离开这些越来越远了,但总能遥想以前,我总能想起自己做nokia的WindowsLive的ui自动化,做web的自动化测试, ...

  4. 网易与Google合作发布开源UI自动化测试方案 牛逼:Google 方面评价,这可能是目前世界上最好的 Android 游戏自动化测试方案。

    美西时间 3 月 19 日,在 GDC 开幕第一天的 Google 开发者专场,Google 发布了一款由网易研发的 UI 自动化测试方案:Airtest Project.Google 方面评价,这可 ...

  5. APP的UI自动化测试框架及平台化探索

    顾铮,10年+测试及测试开发相关经验,2014年加入京东,曾主导设计开发UI测试框架,参与CI测试平台建设,现负责iOS侧的工具,框架建设.在UI自动化,性能测试,单元测试方面有较深入研究,在App, ...

  6. Airtest网易开源的一款UI自动化测试工具

    Airtest网易开源的一款UI自动化测试工具 1 Airtest 简介Airtest Project是网易游戏内部工具团队开发并开源的一款UI自动化测试工具,据说曾经获得谷歌力挺. AirtestI ...

  7. Python+appium+unittest UI自动化测试

    什么是UI自动化 自动化分层 单元自动化测试,指对软件中最小可测试单元进行检查和验证,一般需要借助单元测试框架,如java的JUnit,python的unittest等 接口自动化测试,主要检查验证模 ...

  8. atx测试框架实现手机应用UI自动化测试

    最近工作中遇到游戏APP需要实现UI自动化测试,这个app中真的是典型的混合App,有Android原生控件,有webview控件,以及游戏操作页面.研究了Appium,发现appium实现跨应用操作 ...

  9. 网易与Google合作,于GDC开幕首日发布开源UI自动化测试方案

    [TechWeb报道]美西时间3月19日,在GDC开幕第一天的Google开发者专场,Google发布了一款由网易研发的UI自动化测试方案:Airtest Project. Google方面评价,这可 ...

随机推荐

  1. <a href="#">什么意思

    转自:https://zhidao.baidu.com/question/67668291.html <a href="#">是链接到本页,因为你有的时候需要有个链接的 ...

  2. 3.1-3.3 HBase Shell创建表

    一.HBase Shell创建表 1.HBASE shell命令 ## hbase(main):001:0> create_namespace 'ns1' //创建命名空间:ns1 hbase( ...

  3. 用JavaScript方式创建easyUI datagrid Column Group(列组)

    代码如下: <script type="text/javascript"> var datagrid; $(function(){ $('#datagrid').dat ...

  4. 详细讲解:零知识证明 之 zk-SNARK 开篇

    作者:林冠宏 / 指尖下的幽灵 博客:http://www.cnblogs.com/linguanh/ 掘金:https://juejin.im/user/587f0dfe128fe100570ce2 ...

  5. 进击python第三篇:基础

    基础拾遗 序列解包 例: >>>x,y,z=1,2,3 >>>print x,y,z 1 2 3 交换变量也是没问题 >>>x,y=y,x > ...

  6. Trie树(小)总结 By cellur925

    关于\(Trie\)树的详细介绍,还请移步这篇深度好文 基本操作 插入 void insert() { int p=0; int len=strlen(tmp+1); for(int i=1;i< ...

  7. VC++6.0下新建工程中有17个选项,都是做什么用的?

    要理解每种工程的作用需要很多基础知识,只能简要的和你讲一下: 1.ATL COM AppWizard 用来新建一个COM组件的向导,比如WORD里用的公式编辑器就是一个COM组件. 2.Cluster ...

  8. w3c网址和标准化过程

  9. Serervlet | 两种跳转方式

    https://www.cnblogs.com/fanhc/archive/2012/09/21/2696343.html response.sendRedirect是向客户浏览器发送页面重定向指令, ...

  10. Guard Duty (medium) Codeforces - 958E2 || (bzoj 2151||洛谷P1792) 种树 || 编译优化

    https://codeforces.com/contest/958/problem/E2 首先求出N个时刻的N-1个间隔长度,问题就相当于在这些间隔中选K个数,相邻两个不能同时选,要求和最小 方法1 ...