IOS UI Automation

显示某个对象的所有属性

var target = UIATarget.localTarget();
var obj= target.frontMostApp().mainWindow().images()["QmenuBut3.png"].rect().origin;
var aaa="";
for(var i in obj) {
aaa = aaa +i+":"+obj[i]+" ";
}

解决Failed to start Instruments daemon for ‘iOS’ on iPhone 3GS (v5.0.1)

Failed to start Instruments daemon for ‘iOS’ on iPhone 3GS (v5.0.1) (The service is invalid.)
Please reconnect the device

近日手机设备连mbp,打开instruments,一直报这个错。重新连接,重启电脑,重启手机,都没办法解决。
后来尝试先打开xcode,等设备信息加载完后,再重新打开instruments。问题居然解决了。

UIALogger.logStart

UIALogger.logStart用于收起显示同一级的log。
使用logStart后,后续的log记录,都会标记为其子集,可收起、展开显示,直到遇到logPass、logFail、logIssue,才结束这一层级。

instruments如何处理alert对话框

被测应用中有出现alert对话框,需要点击处理。绕了很多弯路,回头想想其实很简单。
1. onAlert事件要放在执行代码前面
2. onAlert事件中return值需要为true。如果是false,系统自动点击cancel按钮,如果cancel按钮不存在,则点击默认按钮。
3. 按顺序写执行代码即可

var target = UIATarget.localTarget();

UIATarget.onAlert = function onAlert(alert) {
var title = alert.name();
UIALogger.logWarning(“Alert with title ‘” + title + “‘ encountered.”);
// return false to use the default handler
return true;
}

target.frontMostApp().mainWindow().tableViews()["空列表"].cells()["xxx, 用户注销"].tap();
// Alert detected. Expressions for handling alerts should be moved into the UIATarget.onAlert function definition.
target.frontMostApp().alert().defaultButton().tap();

instruments学习笔记(一)

//调用外部js
#import “../common/common.js”

//导航栏操作
UIATarget.localTarget().frontMostApp().navigationBar().leftButton().tap(); //点击左侧按钮
UIATarget.localTarget().frontMostApp().navigationBar().rightButton().tap(); //点击右侧按钮

//按钮点击
UIATarget.localTarget().frontMostApp().mainWindow().buttons()["xxxxx"].tap();

//坐标点击
UIATarget.localTarget().tap({x:30,y:131});

//等待n秒,delay(n)
UIATarget.localTarget().delay(3);

//截图
UIATarget.localTarget().captureScreenWithName(“picname”);

//获取对象数组长度,length
UIATarget.localTarget().frontMostApp().mainWindow().buttons().length;

//获取文本字符串,value()
UIATarget.localTarget().frontMostApp().mainWindow().scrollViews()[0].staticTexts()[0].value();

//滚轮滚动,dragInsideWithOptions()
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});

//根据name模糊查询控件,firstWithPredicate(“name beginswith ‘xxx’”)
obj= window.tableViews()[0].cells().firstWithPredicate(“name beginswith ‘hello’”);

//根据name完全匹配,firstWithName(“xxxx”)
obj= window.tableViews()[0].cells().firstWithName(“hello world”);

//根据key值匹配,firstWithValueForKey(value,key)
obj= window.tableViews()[0].cells().firstWithValueForKey(“hello world”,”name”);

//拖动
window.tableViews()[0].scrollDown();
window.tableViews()[0].scrollUp();
window.tableViews()[0].scrollLeft();
window.tableViews()[0].scrollRight();

//打印当前屏幕所有空间信息
UIATarget.localTarget().logElementTree();

//记录日志
UIALogger.logStart(“start”);
UIALogger.logPass(“pass”);
UIALogger.logWarning(“warning”);
UIALogger.logFail(“fail”);
UIALogger.logMessage(“message”);
UIALogger.logError(“error”);
UIALogger.logDebug(“debug”);
UIALogger.logIssue(“issue”);

//九宫格搜索输入框
UIATarget.localTarget().frontMostApp().mainWindow().searchBars()[0]

//模拟键盘操作,keyboard().typeString(“xxx”)
UIATarget.localTarget().frontMostApp().keyboard().typeString(“aaa\n”);

\n=回车

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


原文出自 http://www.vingo.cn/vingo/?tag=ui-automation IALogger.logPass("obj:"+aaa);
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值