- 授权协议: 未知
- 开发语言: Java
- 操作系统: 跨平台
- 软件首页: https://github.com/NetEase/arrow
软件介绍
TestNG 是一个设计用来简化广泛测试需求的 测试框架,旨在涵盖所有类型的测试,包括单元测试、功能测试、端到端集成测试等,而我们在基于TestNG搭建自动化测试框架,编写测试用例时,为保证测试用例的稳定性,需要增加测试用例失败自动重跑功能,这便促成了Arrow 的诞生。 Arrow是基于TestNG监听器扩展的插件,如果把TestNG比作一把强劲的弓,那么插件就是配合弓使用的箭,这也是Arrow命名的由来。
一、Arrow功能介绍
1、 支持通过简单配置实现失败的测试用例自动重跑
2、 支持Html结果报告中展示测试用例运行次数
3、 支持自动解析源代码中的@author标签,在Html结果报告中展示(失败用例可以方便查找维护者)
4、 修复TestNG原生Html报告中锚点跳转不正确的Bug
俗话说,眼见为实耳听为虚,下面就带大家看看实际效果图吧!
二、Arrow使用效果
使用Arrow插件运行基于TestNG的测试用例后会生成我们自定义的报告power-emailable-report.html,下图1显示 在测试用例中书写@author标签,使用arrow执行完用例后生成如图2的结果报告,报告中会自动读取authors信息以及running counts运行次数,通过authors信息方便自动获取到该用例的维护者,通过running counts方便知道当前用例是否失败重跑。
图1
图2
三、如何使用Arrow
使用Arrow无需修改原有的测试代码
1、 首先你需要有一套TestNG编写的测试用例
2、 测试工程中需要testng.jar(核心不能忘!),log4j.jar(用于日志的输出)以及我们提供的arrow.jar
3、 测试工程根目录下新建config.properties文件,同时配置如下参数
retrycount=1 #定义重跑次数,不是必填项, 默认值是0,即失败不重跑 sourcecodedir=src #定义源代码路径,不是必填项, 默认值是src sourcecodeencoding=UTF-8 #定义源代码编码,不是必填项,默认值是utf-8
4、 在build.xml文件中加入监听器,配置如下,配置完成后通过ant运行TestNG测试用例后可以在生成的Html结果报告中查看效果
<target name="testng"> <mkdir dir="test-output" /> <testng outputDir="test-output" haltonfailure="false" listeners="com.netease.qa.testng.PowerEmailableReporter, com.netease.qa.testng.RetryListener, com.netease.qa.testng.TestResultListener"> <xmlfileset dir="." includes="testng.xml" /> </testng> </target>
5、 如果您不习惯4的做法,可以在testng.xml中加入如下的监听器,配置完成后右键testng.xml文件运行测试用例即可
<listeners> <listener class-name="com.netease.qa.testng.TestResultListener" /> <listener class-name="com.netease.qa.testng.RetryListener" /> <listener class-name="com.netease.qa.testng.PowerEmailableReporter" /> </listeners>
四、Arrow扩展-失败用例自动截图
由于截图功能在不同的测试框架上API会不同,所以当前Arrow中没有把这个功能集成进来,但是如果你需要该功能也可以很方便的进行扩展。
1、 下载Arrow的源代码
2、 修改TestResultListener类,在onTestSkipped以及onTestFailure方法中加入如下代码
@Override
public void onTestFailure(ITestResult tr) {
super.onTestFailure(tr);
saveScreenShot(tr);
}
@Override
public void onTestSkipped(ITestResult tr) {
super.onTestSkipped(tr);
saveScreenShot(tr);
}
private void saveScreenShot(ITestResult tr) {
SimpleDateFormat formatter = new SimpleDateFormat("yyyy_MM_dd_HH_mm_ss");
String mDateTime = formatter.format(new Date());
String fileName = mDateTime + "_" + tr.getName();
String filePath = "";
try {
//这里可以调用不同框架的截图功能
File screenshot = ((TakesScreenshor)webdriver).getScreenshotas(OutputType.FILE);
filePath = “screenshot/” + filename + “.jpg”
File destFile = new File(filePath);
FileUtils.copyFile(screenshot, destFile);
} catch (Exception e) {
filePath = fileName + " firefox tackScreentshot Failure:" + e.getMessage();
logger.error(filePath);
}
if (!"".equals(filePath)) {
Reporter.setCurrentTestResult(tr);
Reporter.log(filePath);
//把截图写入到Html报告中方便查看
Reporter.log("<img src=\"../" + filePath + "\"/>");
}
}
3、修改完成后重新运行测试用例,即可实现失败自动截图,同时会把截图写入到Html结果报告中,方便定位问题,如图3。
图3
最后,欢迎大家使用以及共同改进Arrow,方便大家基于TestNG的测试工作。
介绍来自:http://qa.blog.163.com/blog/static/1901470022014245230459/
Introduction to Computation and Programming Using Python
John V. Guttag / The MIT Press / 2013-7 / USD 25.00
This book introduces students with little or no prior programming experience to the art of computational problem solving using Python and various Python libraries, including PyLab. It provides student......一起来看看 《Introduction to Computation and Programming Using Python》 这本书的介绍吧!
