获得当前程序窗口:
var target = UIATarget.localTarget();//获得目标程序
var window = target.frontMostApp().mainWindow();//获得当前窗口
坐标点击:target.tap({x:322,y:21});
元素点击:target.frontMostApp().mainWindow().buttons()["xxx"].tap();//可以使用Xcode-instruments-Automation工具录制获取
划屏:target.flickFromTo({x:20,y:150},{x:12,y:446});
判断元素是否存在:
if(target.frontMostApp().mainWindow().elements()["加入购物车"].isVisible()){
UIALogger.logPass("在售状态,进行加入购物车操作");
target.frontMostApp().mainWindow().buttons()["加入购物车"].tap();
target.delay(5);
}
else{
UIALogger.logFail("已抢光,不进行加入购物车操作");
target.delay(2);
}
等待系统等待:target.delay(2);//延时2秒执行下一条指令
target.pushTimeout(2);//指定超时为2秒钟
target.popTimeout();//超时弹出
打印日志:
UIALogger.logStart("————————开始进行[搜索]页浏览操作————————");
UIALogger.logIssue("~~~~~~点击【购物车】按钮~~~~~~~");
UIALogger.logWarning("开始进行浏览第1个商品操作");
......
修改提示弹框可以点击确定按钮:
UIATarget.onAlert = function onAlert(alert){
var title = alert.name();
return true;
}
打印控件树结构:target.logElementTree();
截图:target.captureScreenWithName(“picname”);
target.captureScreenWithName("HomePage");//抓取当前测试的屏幕保存名字为:HomePage
虚拟键盘操作:
target.frontMostApp().keyboard().typeString(“xxx”);
scrollView定位:
target.frontMostApp().mainWindow().tableViews()[0].scrollToElementWithPredicate("name beginswith ‘Turtle Pie’");//滚动到表格名字以Turtle Pie开头的地方.名字可是不确定的,可以用这个方法来定位.
scrollToElementWithName() 名字确定的位置
scrollToElementWithValueForKey()值确定的位置.
instruments -w d3e6061d40b52e160a77ad7a80af980a5fb00777 -t "/Applications/Xcode.app/Contents/Applications/Instruments.app/Contents/PlugIns/AutomationInstrument.xrplugin/Contents/Resources/Automation.tracetemplate" com.lafaso.iphone -e UIASCRIPT /Users/One/ios_perfomance_test/Monkey_sh/APPLogin/LeFeng.js