• 手机版

    扫码体验手机版

  • 微信公众号

    扫码关注公众号

国内首家协议开发

软芯音视解码保护平台

在线
客服

发布
需求

在线
聊天

天盟
APP

天盟APP下载

关注
微信

微信扫一扫访问
顶部

ios UI自动化测试学习笔记

一、一些注意事项:

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中导航
133002zldn79du8t7yvdu1.jpg

var tabBar = UIATarget.localTarget().frontMostApp().mainWindow().tabBar(); var selectedTabName = tabBar.selectedButton().name(); if (selectedTabName != "Unit Conversion") { tabBar.buttons()["Unit Conversion"].tap();}
133004bmjiyywf6c6ycbzq.jpg

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.增加时间控制:
133004aib3cuourqc3srq0.jpg

//压栈时间片:UIATarget.localTarget().pushTimeout(2);//接着执行脚本任务;//时间片出栈UIATarget.localTarget().popTimeout();
133004o3xvdhzux83ugpxx.jpg

还有一种方式,采用delay方式:
UIATarget.localTarget().delay(2);两种方式的区别是,在时间片内,第一种方法会不断尝试去执行压栈和出栈间的脚本任务,一旦可以执行就执行,不一定在时间片后才执行,而第二种方式是在时间片到后才执行脚本任务。
13.按钮点击:
UIATarget.localTarget().frontMostApp().mainWindow().buttons()["xxxxx"].tap();14截屏功能,事实证明模拟器是能使用截屏功能的:
UIATarget.localTarget().captureScreenWithName("SS001-2_AddedIngredient");15.验证结果:
133004cp4tgcgggytgzqxy.jpg

var cell = UIATarget.localTarget().frontMostApp().mainWindow().tableViews()[0].cells().firstWithPredicate("name beginswith ‘Tarte’");if (cell.isValid()) {UIALogger.logPass(testName);}else {UIALogger.logFail(testName);}
133004keeeevel0e4i4z5p.jpg

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

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;}
133004iuhhh0ctc33cfk3l.jpg

返回FALSE代表点击取消,TRUE代表确定。
17.模拟后台一段时间:
UIATarget.localTarget().deactivateAppForDuration(10);手机方向旋转:
UIATarget.localTarget().setDeviceOrientation(UIA_DEVICE_ORIENTATION_PORTRAIT);18.拖动
133004lss8s11kpcr8vbbm.jpg

window.tableViews()[0].scrollDown();window.tableViews()[0].scrollUp();window.tableViews()[0].scrollLeft();window.tableViews()[0].scrollRight();
133004jpwsos5opffs7k7a.jpg

19.打印当前屏幕所有空间信息
UIATarget.localTarget().logElementTree();20.记录日志
133004r508o5f4lfojnunl.jpg

UIALogger.logStart(“start”);UIALogger.logPass(“pass”);UIALogger.logWarning(“warning”);UIALogger.logFail(“fail”);UIALogger.logMessage(“message”);UIALogger.logError(“error”);UIALogger.logDebug(“debug”);UIALogger.logIssue(“issue”);
133004h1h5su1s8etf3egt.jpg


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});http://www.yx-guangzhou.com/
http://www.yx-guangzhou020.com/
http://yx-shenzhen.com/
http://www.yx-xiamen.cn/
http://szkfpyxcs0755.wikidot.com/
http://szdkfpyxcs0755.wikidot.com/nav:side
http://szdkfwfpyxcs0755.wikidot.com/
http://szdkjdfpyxcs0755.wikidot.com/start
http://szdkjcfpyxcs0755.wikidot.com/start
http://szfp06.wikidot.com
http://szfp07.wikidot.com
http://szfp08.wikidot.com
http://szfp09.wikidot.com
http://szfp10.wikidot.com
http://fp011.wikidot.com/
http://fp012.wikidot.com/
http://zsfp01.wikidot.com/
http://dgkfp01.wikidot.com/
http://szkfp02.wikidot.com/chatter:_template
http://guangzhouzsf.wikidot.com/
https://cnkdshfcdnk.weebly.com/
https://dsvnkdnbvjd.weebly.com/
https://jhbjgjgjkhj.weebly.com/
https://dsmchjdfns.weebly.com/
https://bg9gybkjg.weebly.com/
https://bnohfvlss.weebly.com/
https://luhaonanffda.weebly.com/
https://hkfofjwpq.weebly.com/
https://fdlnfdjgh.weebly.com/
https://yx-guangzhou.weebly.com/
https://weidian.com/?userid=1372845365

免责声明:本内容仅代表回答会员见解不代表天盟观点,请谨慎对待。

版权声明:作者保留权利,不代表天盟立场。

使用道具 举报

发新帖

发布任务需求已有1031167位用户正在使用天盟网服务

发布分类: *
任务预算: *
需求内容: *
手机号码: *
任务商家报价为
  • 预算价 :
  • 成交价 :
  • 完工期 :
  • 质保期 :

* 最终任务项目以服务商报价、双方协商为准!