关于ios使用Automation自动测试
2013-09-29 14:29
369 查看
最近看了一篇英文文章觉得写的非常好,所以根据本人所学总结过来,不过英文水平有限,只能半猜半测试的弄过来,先说明本人主攻技术,所以英文如果翻译有错,请多担待。
自动测试可以测试性能等,学习之前,先讲讲需要用到的工具:xcode需要4.0以上,不过4.5以上commond-line可以截图和使用脚本。
从xcode4.0以后就增加了一个UIAutomation框架,既可以用在模拟器也能用在真机上。有文档可以参看参考资料。
首先,如果不想自己写例子就下载一个参考资料1中的例子吧,先在模拟器上使用吧。使用Product > Profile命令启动,可看到instruments启动了,这时选择profile,
进入了Automation,先点击红色按钮停止。
这个时候可以写script了,也可以import一个js文件,这两种都可以通过左侧的scripts里面的add按钮进行操作:
这里就懒得create了,直接import一个例子中写好的js文件吧。
将右侧的显示区设置为script区:
可以看到里面的内容变成了:
var testName = "Test 1";
var target = UIATarget.localTarget();
var app = target.frontMostApp();
var window = app.mainWindow();
//--
UIALogger.logStart( testName );
app.logElementTree();
//-- select the elements
UIALogger.logMessage( "Select the first tab" );
var tabBar = app.tabBar();
var selectedTabName = tabBar.selectedButton().name();
if (selectedTabName != "First") {
tabBar.buttons()["First"].tap();
}
//-- tap on the text fiels
UIALogger.logMessage( "Tap on the text field now" );
var recipeName = "Unusually Long Name for a Recipe";
window.textFields()[0].setValue(recipeName);
target.delay( 2 );
//-- tap on the text fiels
UIALogger.logMessage( "Dismiss the keyboard" );
app.logElementTree();
app.keyboard().buttons()["Return"].tap();
var textValue = window.staticTexts()["RecipeName"].value();
UIALogger.logMessage( "text value=" + textValue );
if (textValue === recipeName){
UIALogger.logPass( testName );
}
else{
UIALogger.logFail( testName );
}
点击红色按钮运行一下吧,可以看到一系列的动作出现了,都是自动的哦。下面就来进行详细的分析一下吧。不过今天不太想写了,所以还是明天来吧。这些代码很简单,一看基本就明白了。不过明天还是会进行详细解说的。
参考资料:
1、iOS Automated Tests with UIAutomation
2、UI Automation JavaScript Reference
3、About Instruments
4、wwdc
自动测试可以测试性能等,学习之前,先讲讲需要用到的工具:xcode需要4.0以上,不过4.5以上commond-line可以截图和使用脚本。
从xcode4.0以后就增加了一个UIAutomation框架,既可以用在模拟器也能用在真机上。有文档可以参看参考资料。
首先,如果不想自己写例子就下载一个参考资料1中的例子吧,先在模拟器上使用吧。使用Product > Profile命令启动,可看到instruments启动了,这时选择profile,
进入了Automation,先点击红色按钮停止。
这个时候可以写script了,也可以import一个js文件,这两种都可以通过左侧的scripts里面的add按钮进行操作:
这里就懒得create了,直接import一个例子中写好的js文件吧。
将右侧的显示区设置为script区:
可以看到里面的内容变成了:
var testName = "Test 1";
var target = UIATarget.localTarget();
var app = target.frontMostApp();
var window = app.mainWindow();
//--
UIALogger.logStart( testName );
app.logElementTree();
//-- select the elements
UIALogger.logMessage( "Select the first tab" );
var tabBar = app.tabBar();
var selectedTabName = tabBar.selectedButton().name();
if (selectedTabName != "First") {
tabBar.buttons()["First"].tap();
}
//-- tap on the text fiels
UIALogger.logMessage( "Tap on the text field now" );
var recipeName = "Unusually Long Name for a Recipe";
window.textFields()[0].setValue(recipeName);
target.delay( 2 );
//-- tap on the text fiels
UIALogger.logMessage( "Dismiss the keyboard" );
app.logElementTree();
app.keyboard().buttons()["Return"].tap();
var textValue = window.staticTexts()["RecipeName"].value();
UIALogger.logMessage( "text value=" + textValue );
if (textValue === recipeName){
UIALogger.logPass( testName );
}
else{
UIALogger.logFail( testName );
}
点击红色按钮运行一下吧,可以看到一系列的动作出现了,都是自动的哦。下面就来进行详细的分析一下吧。不过今天不太想写了,所以还是明天来吧。这些代码很简单,一看基本就明白了。不过明天还是会进行详细解说的。
参考资料:
1、iOS Automated Tests with UIAutomation
2、UI Automation JavaScript Reference
3、About Instruments
4、wwdc
相关文章推荐
- 关于jmeter里的自动重定向的使用-小强性能测试培训班学生作品
- 关于字符和数字类型的索引,Oracle如何实现内部自动转换以及索引使用的验证测试
- 关于jmeter里的自动重定向的使用-小强性能测试培训班学生作品
- 关于字符和数字类型的索引,Oracle如何实现内部自动转换以及索引使用的验证测试
- iOS.swift 关于swift的自动布局snapkit第三方的使用记录
- iOS 平台如何使用 TestFlight 进行 Beta 测试
- IOS关于UITabBarController的使用
- 详解iOS应用程序内使用IAP/StoreKit付费,沙盒(SandBox)测试,创建测试账号流程
- ATS的诊断工具:测试iOS使用的HTTPS地址是否符合ATS的规则
- iOS关于Button使用的一些总结
- ios中关于delegate(委托)的使用心得
- iOS 8 Auto Layout界面自动布局系列2-使用Xcode的Interface Builder添加布局约束
- IOS开发之关于cocoaPods 第三方的使用
- 关于iOS测试机个数上限的详细规则
- Android 中使用JUnit进行自动测试
- iOS 使用Kiwi测试框架进行测试
- IOS开发:关于performSelectorXXX的延迟的使用
- IOS 关于内置高德地图的使用(三)
- rsyslog客户端自动部署脚本,经测试使用正常
- 关于springmvc 中的Controller使用自动装配失败的解决方法