Java发送reportng报告邮件,定制并优化reportng生成测试报告

定制并优化reportng生成测试报告

2018-11-20

1.首先,我们得去github上下载reportng源码。ReportNG Source Code Download:https://github.com/dwdyer/reportng源码使用的是Intellij+Maven+Ant+TestNG开发的Java项目。我使用的是官网免费的IntelliJ IDEA Community Edition 2016.2Intellij下载和安装地址:http://www.360doc.com/content/16/0803/16/32074671_580528432.shtml2.然后,导入maven工程代码,并处理掉报错。

32074671_201608031434430376881102.png3.修改ReportNGUtils类。/*** @author Sunny* @param driver* @param baseDir* @return*/public static String getImageString(WebDriver driver, String baseDir) {String imgName = generateFileNameWithPrefix();File srcFile = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);try {FileUtils.copyFile(srcFile, new File(baseDir + File.separator+ imgName));} catch (IOException e) {// TODO Auto-generated catch blocke.printStackTrace();}return imgName;}public static String removeImage(String imgName) {return imgName.replaceAll("","");}public static String generateFileNameWithPrefix() {final DateFormat ExcuteTime_FILE_NAME = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM);String fileName = ExcuteTime_FILE_NAME + ".png";return fileName;}4.修改ReportMetadata类,为了处理打开的index.html时间显示乱码。

32074671_201608031432090752504264.png将原字段DATE_FORMAT属性改为:private static Locale locale = new Locale("en", "US");private static final DateFormat DATE_FORMAT = DateFormat.getDateInstance(DateFormat.FULL, locale);5.修改TestResultComparator类。public int compare(ITestResult result1, ITestResult result2){/*** @author Sunny* Update veriable longresult2*/// return result1.getName().compareTo(result2.getName());int longresult2 = 0;if (result1.getStartMillis() < result2.getStartMillis()) {longresult2 = -1;} else {longresult2 = 1;}return longresult2;}6.修改reportng.properties文件,自定义oneclass属性值。oneclass.description=Descriptiononeclass.duration=Durationoneclass.testdata=Data being usedoneclass.testresult=Test resultoneclass.screenshot=Screen shotoneclass.additionalinfo=Additional Info7.修改class-results.html.vm,将源码修改为

#set ($output = $utils.getTestOutput($testResult))#if ($output.size() > 0)
#foreach( $line in $output )#if ($meta.shouldEscapeOutput())$utils.escapeHTMLString($utils.getImageString($line))
#else$utils.getImageString($line)
#end#end
#end8.修改results.html.vm文件, fail是本次需要修改的、skipped可根据需要来修定。#if ($failedTests.size() > 0)
$messages.getString("failedTests")
$testClass.name ⁄ $messages.getString("oneclass.duration")$messages.getString("oneclass.description")$messages.getString("oneclass.testdata")$messages.getString("oneclass.testresult")$messages.getString("oneclass.screenshot")
#end#if ($skippedTests.size() > 0)
$testClass.name ⁄ $messages.getString("oneclass.duration")
$testClass.name$messages.getString("oneclass.description")$messages.getString("oneclass.testdata")$messages.getString("oneclass.testresult")$messages.getString("oneclass.screenshot")
#end9.源码修改基本完成,接下来就是测试与打包。由于author使用的是很老的Ant打包。使用Intellij Ant打包地址:http://www.360doc.com/showWeb/0/0/580535169.aspx原出处(结合两者):https://testerhome.com/topics/3594http://tech.it168.com/a2013/0906/1530/000001530755_3.shtml

免责声明:本文仅代表文章作者的个人观点,与本站无关。其原创性、真实性以及文中陈述文字和内容未经本站证实,对本文以及其中全部或者部分内容文字的真实性、完整性和原创性本站不作任何保证或承诺,请读者仅作参考,并自行核实相关内容。

http://www.pinlue.com/style/images/nopic.gif

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值