iphone/ipad 自动化测试 Demo(XCode4.5.1)
来源:互联网 发布:太极越狱mac版 编辑:程序博客网 时间:2024/06/11 18:09
最近,在进行iOS程序的开发,后期需要进行一点自动测试,就查找了一些相关的资料,note here,希望对大家有帮助~~
iOS自动化脚本采用的是JS来编写的,为了节省时间,我采用的是首先录制屏幕操作,然后,再根据程序逻辑来更改代码。
JS教程:http://www.w3schools.com/js/js_howto.asp
一个非常好的XCode Automation 教程: http://blog.manbolo.com/2012/04/08/ios-automated-tests-with-uiautomation#3.4
Automation对象的reference:http://developer.apple.com/library/ios/#documentation/DeveloperTools/Reference/UIAutomationRef/_index.html
一、 编写自己的测试脚本
建议把上面所有的资料看一边,在具体的进行自己自动化测试。
下面是我自己进行修改的JS测试脚本,仅供参考:
- var target = UIATarget.localTarget();
- UIATarget.onAlert = function onAlert(alert) {
- var title = alert.name();
- UIALogger.logMessage("Alert View " + title + " encountered!");
- if(title == "请输入") {
- UIALogger.logMessage("请输入");
- target.frontMostApp().alert().textFields()[0].tap();
- target.frontMostApp().keyboard().typeString("300");
- return false;
- }
- return false;
- }
- target.frontMostApp().mainWindow().textFields()[0].tap();
- target.frontMostApp().keyboard().keys()["Delete"].tapWithOptions({tapCount:5});
- target.frontMostApp().keyboard().typeString("xxxx");
- target.frontMostApp().mainWindow().secureTextFields()[0].tap();
- target.frontMostApp().keyboard().typeString("1234");
- target.frontMostApp().navigationBar().rightButton().tap();
- while(target.frontMostApp().navigationBar().name() == "登录") {
- UIALogger.logMessage("LoginView: " + target.frontMostApp().navigationBar().name());
- target.delay(1); //此处参看http://stackoverflow.com/questions/3651316/handling-alert-with-uiautomation
- }
- UIALogger.logMessage(target.frontMostApp().navigationBar().name());
- if(target.frontMostApp().navigationBar().name() == "授权") {
- target.frontMostApp().mainWindow().textFields()[0].tap();
- target.frontMostApp().keyboard().typeString("092888");
- target.frontMostApp().navigationBar().rightButton().tap();
- }
- while(target.frontMostApp().navigationBar().name() == "授权") {
- UIALogger.logMessage("AuthoView: " + target.frontMostApp().navigationBar().name());
- target.delay(1);
- }
- var roundNum = 100;
- UIALogger.logMessage(target.frontMostApp().navigationBar().name());
- if(target.frontMostApp().navigationBar().name() == "主页") {
- while(roundNum-- > 0){
- target.frontMostApp().navigationBar().leftButton().tap();
- // Alert detected. Expressions for handling alerts should be moved into the UIATarget.onAlert function definition.
- target.delay(2);
- var boxNum = 30;
- if(target.frontMostApp().navigationBar().name() != "主页") {
- while(boxNum-- > 0) {
- UIALogger.logMessage(target.frontMostApp().navigationBar().name());
- target.frontMostApp().mainWindow().buttons().firstWithName("1").tap();
- target.frontMostApp().mainWindow().buttons().firstWithName("0").tap();
- target.frontMostApp().mainWindow().buttons()["x"].tap();
- target.frontMostApp().mainWindow().buttons()["xx"].tap();
- target.frontMostApp().mainWindow().buttons()["xx"].tap();
- target.frontMostApp().mainWindow().buttons()["xx"].tap();
- target.frontMostApp().mainWindow().buttons()["xx"].tap();
- target.frontMostApp().mainWindow().buttons().firstWithName("8").tap();
- target.frontMostApp().mainWindow().buttons()["xxx"].tap();
- target.frontMostApp().mainWindow().buttons()["确定"].tap();
- }
- target.frontMostApp().navigationBar().segmentedControls()[0].buttons()["stop_normal.png"].tap();
- // Alert detected. Expressions for handling alerts should be moved into the UIATarget.onAlert function definition.
- target.delay(2);
- }
- }
- }
二、在命令行运行测试脚本
如果要使用命令行来运行测试脚本, 上面给出的XCode Automation 里面的命令是对的,但是对于Xcode4.5.1 还需要进行相应的修改。
因为自动化测试的模板和Xcode.app的位置都与之前的不同,需要分别进行确定:
首先,定位Automation.tracetemplate, 使用命令:
locate Automation.tracetemplate 或者 find / -type f -name "Automation.tracetemplate"
然后,执行:
sudo xcode-select -switch /Applications/Xcode.app (此处也可先找到Xcode.app的路径,方法同上)
最终,在真机上面测试的命令如下:
instruments -w ****************** -t /Applications/Xcode.app/Contents/Applications/Instruments.app/Contents/PlugIns/AutomationInstrument.bundle/Contents/Resources/Automation.tracetemplate TestApp -e UIASCRIPT /gtliuData/Instruments/iOSAutoTestJS/SecondTest.js- iphone/ipad 自动化测试 Demo(XCode4.5.1)
- iphone、ipad自动化测试,解决方案
- iPhone App自动化测试
- iPhone自动化测试
- iPhone自动化测试
- iPhone App自动化测试
- iOS ipad和iphone兼容~demo
- Oc iPad与iPhone兼容~demo
- selenium c# 自动化测试demo
- iPhone(iPad) Simulator 测试程序配置
- Appium移动自动化测试(三)——python demo
- Appium移动自动化测试(四)--one demo
- webUI自动化测试框架(一):简介和Demo入门
- Appium移动自动化测试(四)--one demo
- Selenium+Python进行web自动化测试(Demo+API)
- xcode4.6.1 iphone 5 ios 6 免证真机测试
- xcode4.6.1 iphone 5 ios 6 免证真机测试
- sikuli自动化测试环境搭建和demo
- 栈求最小值
- 冒泡排序
- 坚强了太久,我会累_忧伤心情日志
- VMvare Workstation 9.0下安装Fedora 17图文教程(二)——安装Fedora 17
- Emacs Lisp List
- iphone/ipad 自动化测试 Demo(XCode4.5.1)
- linux 分区 挂载点之间的关系
- 排序选择算法--java--之高效率篇
- 每个人的QQ里 都有一个这样的人
- Mahout-从Cluster看类扩展理念
- MyEclipse编码设置
- Linux操作系统文件系统基础知识详解
- V4L2下 mmap 多帧采集
- 调色盘 (3维k点最小最远点对-容斥原理)