一、一些注意事项:

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. UI设计学习笔记(7-12)

    UI学习笔记(7)--扁平化图标 认识扁平化 Flat Design 抛弃传统的渐变.阴影.高光等拟真视觉效果,打造看上去更平的界面.(颜色.形状) 扁平化图标有什么优缺点 优点: 简约不简单.有新鲜 ...

  2. IOS内存管理学习笔记

    内存管理作为iOS中非常重要的部分,每一个iOS开发者都应该深入了解iOS内存管理,最近在学习iOS中整理出了一些知识点,先从MRC开始说起. 1.当一个对象在创建之后它的引用计数器为1,当调用这个对 ...

  3. [XMPP]iOS聊天软件学习笔记[一]

    @import url(http://i.cnblogs.com/Load.ashx?type=style&file=SyntaxHighlighter.css);@import url(/c ...

  4. selenium2自动化测试学习笔记(三)

    今天是学习selenium的第三天,今天的主题是自动登录126邮箱. 今天总结碰到的坑有三个: 1.frame内元素抓取,使用driver.switch_to.frame(frameId)方法切换锁定 ...

  5. selenium2自动化测试学习笔记(一)

    从这周开始学习自动化测试,采用selenium2,目标是在本月学习到appium,并测试公司的真实APP项目. 系统环境:win10 语言:python3.6.4 工具:selenium2 IDE:p ...

  6. jquery UI 跟随学习笔记——拖拽(Draggable)

    引言 这周暂时没有任务下达,所以老大给我的任务就是熟悉jquery相关插件,我就先选择了jquery UI插件,以及jquery库学习. 我用了两天的时候熟悉Interactions模块中的Dragg ...

  7. iOS开发ReactiveCocoa学习笔记(六)

    RAC操作方法三. demo地址:https://github.com/SummerHH/ReactiveCocoa.git doNext deliverOn timeout interval del ...

  8. python自动化测试学习笔记-10YAML

    之前学习的编写测试用例的方法,都是从excel中编写接口的测试用例,然后通过读取excel文件进行接口自动化测试,这种方式我们叫做数据驱动的方式,由于excel操作起来不灵活,无法实现关联关系的接口测 ...

  9. python自动化测试学习笔记-5常用模块

    上一次学习了os模块,sys模块,json模块,random模块,string模块,time模块,hashlib模块,今天继续学习以下的常用模块: 1.datetime模块 2.pymysql模块(3 ...

随机推荐

  1. leetcode笔记(七)529. Minesweeper

    题目描述 Let's play the minesweeper game (Wikipedia, online game)! You are given a 2D char matrix repres ...

  2. JSP/Servlet开发——第一章 动态网页基础

    1.动态网页:在服务端运行的使用程序语言设计的交互网页 : ●动态网站并不是指具有动画功能的网站,而是指网站内容可根据不同情况动态变更的网站(股票网站),一般情况下动态网站通过数据库进行架构. ●动态 ...

  3. typecho博客组插件:openSug.js百度搜索框下拉提示免费代码

      Typecho候选搜索增强插件:安装openSug插件即可获得带有“搜索框提示”功能的搜索框,让Typecho搜索更便捷! 支持百度.谷歌.雅虎.Yandex.360好搜.UC神马.酷狗.优酷.淘 ...

  4. 在Pycharm中导入第三方模块库(诸如:matplotlib、numpy等)

    在Pycharm中导入第三方模块库 一.打开pycharm: 二.点击菜单上的“file” -> “setting”: 三.步骤二完成后出现界面如下所示.选中你的项目(比如thisyan Pro ...

  5. CentOS 同步时间的方法

    与时间服务器上的时间同步的方法 1.  安装ntpdate工具 # yum -y install ntp ntpdate 2.  设置系统时间与网络时间同步 # ntpdate cn.pool.ntp ...

  6. Python学习 :深浅拷贝

    深浅拷贝 一.浅拷贝 只拷贝第一层数据(不可变的数据类型),并创建新的内存空间进行储蓄,例如:字符串.整型.布尔 除了字符串以及整型,复杂的数据类型都使用一个共享的内存空间,例如:列表 列表使用的是同 ...

  7. DJANGO2.0 关联表的必填 ON_DELETE

    DJANGO2.0 关联表的必填 ON_DELETE 参数的含义 - BUXIANGHEJIU 的博客 - CSDN 博客 版权声明:本文为博主原创文章,未经博主允许不得转载. https://blo ...

  8. linux安装python并安装pip

    因为最近要在linux环境下进行python编程,所以就试着去安装了一下,但是网上关于python以及pip的安装说实话有点混乱,所以我今天就把前辈的经验再次总结一下,希望可以给大家提供帮助. pyt ...

  9. C语言:类型、运算符、表达式

    看了一天书,有点累了.就写写随笔记录一下今天的复习成果吧. C语言的基本数据类型 数值型:整型数,浮点数,布尔数,复数和虚数. 非数值型:字符. 整数最基本的是int,由此引出许多变式诸如有符号整数s ...

  10. 洛谷U32670 小凯的数字(比赛)

    题目网址 https://www.luogu.org/problemnew/show/U32670 题目背景 NOIP2018 原创模拟题T1 NOIP DAY1 T1 or DAY 2 T1 难度 ...