您的位置:首页 > 其它

Automating User Interface Testing with Instrument-利用Automation进行自动化测试

2016-05-04 15:31 507 查看

一、需求场景

当我们做好一款app的时候,需要对其进行多次重复的功能测试时很有必要的。目前我做的项目AnyWhere就需要这么一个场景,需要不停的对其进行live和stop,检测crash的log.

原文地址http://blog.csdn.net/Smiling8866/article/details/51315358

二、解决方法

1、对于测试人员:

可以利用Appium,编写脚本进行自动化测试。当然还有其它的工具。这种测试不需要提供源码。

2.对于开发人员:

可以利用Instruments中的Automation框架进行自动化测试,只不过在测试之前需要对源码进行一次profile.

苹果官方提供的有这方面的文档,可以去官网查阅。不过,其给的文档看着有点怪怪的,所以我在下面把它的教程文档给翻译了一下。

原文地址http://blog.csdn.net/Smiling8866/article/details/51315358

三、对Automating User Interface Testing with Instrument 的翻译

1.什么是UI的自动化

Automates UIKit based applications(界面的自动化依赖于app)

Touch based(给予触摸的)

IPhone,iPod touch band IPhone Simulator(支持IPhone,iPod,IPhone模拟器)

Integrate in Instruments(在Instruments中被整合)

Accessibility based (依赖于可接触性)

JavaScript automation scripts (脚本是用js写的)

2.对Elements的介绍

UIAElement——基类元素

Name

Value

Elements

Parent

……没耐心了,不想翻译了。。。

原文地址http://blog.csdn.net/Smiling8866/article/details/51315358

四、我的脚本

原文地址http://blog.csdn.net/Smiling8866/article/details/51315358

var target = UIATarget.localTarget();
var app = target.frontMostApp();
var window = app.mainWindow();
var i = 0;
var totalTimes = 100; // 测试总次数
target.setDeviceOrientation(UIA_DEVICE_ORIENTATION_PORTRAIT);

while(true){
UIALogger.logStart("AnyWherePro Automatic Test");
i++
target.delay(10); // 留10秒的时间刷新RList
window.staticTexts()[9].tapWithOptions({tapOffset:{x:0.38,y:0.46}}); // 点击RList列表
target.delay(2); // 2秒钟展示RList的内容
window.tableViews()[1].tapWithOptions({tapOffset:{x:0.38,y:0.08}}); // 选择R
target.delay(2); // 2秒钟展示选中的R的内容
target.tap({x:132.00,y:298.50}); // 点击屏幕,让RList折叠起来
window.buttons()["begin livingimage"].tap();  // 开始live

var liveButton = window.buttons().withName("stop livingimage");
var screenImage_live = "screenshot_live";
var screenImage_stop = "screenshot_stop";
if(liveButton.isValid()){
UIALogger.logMessage("log info-------"+i+" time--------->start live success..");
target.captureScreenWithName(screenImage_live+i);
}else{
UIALogger.logMessage("log info-------"+i+" time--------->start live failed..");
}
target.setTimeout(30);
target.delay(30); // live 30秒

window.buttons()["stop livingimage"].tap(); // 停止live

liveButton = window.buttons().withName("begin livingimage");
if(liveButton.isValid()){
UIALogger.logMessage("log info-------"+i+" time--------->stop live success..");
target.captureScreenWithName(screenImage_stop+i);
}else{
UIALogger.logMessage("log info-------"+i+" time--------->stop live failed..");
}

if(i == totalTimes){
break;
}
UIALogger.logPass("AnyWherePro Automatic Test");
}
原文地址http://blog.csdn.net/Smiling8866/article/details/51315358


注意:一定要打开手机开发者选项中的允许自动化设置权限
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: