testng生成报告ReportNG美化测试报告

testng生成报告ReportNG美化测试报告

ReportNG 是一个配合TestNG运行case后自动帮你在test-output文件内生成一个相对较为美观的测试报告!
ReportNG 里面Log 是不支持中文的,我改过ReportNG.jar源码,具体方法看最下面,也可以找我直接要jar!
话不多说直接上

环境准备:
1,你需要这些架包

 

解释:有人会问现在ReportNG版本不是1.1.4吗?为什么我这里是1.1.5呢,这里是因为我改过这里面的源码,(为什么要改源码?后面告诉你)
修复ReportNG中文乱码问题包下载地址:地址
2,先写一个简单的case,比如打开百度,下面这个代码看上去不难吧!这是第二步前提是你能运行它

package Test;
import org.junit.After;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxProfile;
import org.testng.annotations.Test; public class case1 { WebDriver driver; @Test
public void Open() throws InterruptedException { System.setProperty("webdriver.friefox.bin","C:\\Program Files\\Mozilla Firefox\\friefox.exe"); FirefoxProfile fp = new FirefoxProfile();
WebDriver driver = new FirefoxDriver(fp);
driver.get("http://www.baidu.com");
driver.findElement(By.id("kw")).sendKeys("testerhome"); } @Test
public void Open() throws InterruptedException { System.setProperty("webdriver.friefox.bin","C:\\Program Files\\Mozilla Firefox\\friefox.exe"); FirefoxProfile fp = new FirefoxProfile();
WebDriver driver = new FirefoxDriver(fp);
driver.get("http://www.baidu.com");
driver.findElement(By.id("kw")).sendKeys("testerhome");
Reporter.log("测试1通过"); } @Test
public void Open1() throws InterruptedException { System.setProperty("webdriver.friefox.bin","C:\\Program Files\\Mozilla Firefox\\friefox.exe"); FirefoxProfile fp = new FirefoxProfile();
WebDriver driver = new FirefoxDriver(fp);
driver.get("http://www.baidu.com");
driver.findElement(By.id("kw")).sendKeys("testerhome");
Reporter.log("测试2通过"); } @Test
public void Open2() throws InterruptedException { System.setProperty("webdriver.friefox.bin","C:\\Program Files\\Mozilla Firefox\\friefox.exe"); FirefoxProfile fp = new FirefoxProfile();
WebDriver driver = new FirefoxDriver(fp);
driver.get("http://www.baidu.com");
driver.findElement(By.id("k1w")).sendKeys("testerhome");
Reporter.log("测试3通过"); } @After
public void quit() throws InterruptedException { driver.quit(); } }

3,配置testNG.xml,这个文件是testNG的配置文件,

<?xml version="1.0" encoding="UTF-8"?>
<suite name="test" parallel="true"> <test name="test" preserver-order="true">
<classes>
//你也可以多个
<class name="包名.case名字"/>
<class name="包名.case名字"/>
<class name="包名.case名字"/>
</classes> <listeners>
//这是你需要加的东西
<listener class-name="org.uncommons.reportng.HTMLReporter" />
<listener class-name="org.uncommons.reportng.JUnitXMLReporter" />
</listeners>

</test> <!-- Test -->
</suite> <!-- Suite -->

4,然后运行testNG.XML ,再看test-output文件夹 里面的 html文件下面的index.html

 

报错信息:

 

你自己System.out的东西都可以写到这里:

 

 

 

如果你的报告是乱码,那么你不要急,方法在下面:

在使用ReportNG替换TestNG自带报告时如果报告中含中文,则会乱码,很是不爽,所以把ReportNG的源码下载下来调试。

原来以为是velocity模板的问题,结果对比发现模板没有任何问题,再通过跟踪生成报告过程的代码发现是在将模板文件替换后输出到页面时未转码导致的,修改方法如下:

修改AbstractReporter中的generateFile这个方法中的代码如下:
原来的代码是这样的:

protected void generateFile(File file,  String templateName,  VelocityContext context) throws Exception{
Writer writer = new BufferedWriter(new FileWriter(file));
try
{
Velocity.mergeTemplate(classpathPrefix + templateName,
ENCODING,
context,
writer);
writer.flush();
}
finally
{
writer.close();
}
}

修改成下面这样,然后编译好新的jar文件

protected void generateFile(File file,  String templateName,  VelocityContext context) throws Exception{
//Writer writer = new BufferedWriter(new FileWriter(file));
//encoding to utf-8
OutputStream out=new FileOutputStream(file);
Writer writer = new BufferedWriter(new OutputStreamWriter(out,"utf-8"));
try
{
Velocity.mergeTemplate(classpathPrefix + templateName,ENCODING,context,writer); writer.flush();
}
finally
{
writer.close();
}
}

这样生成的报告就不会乱码了。

testng生成报告ReportNG美化测试报告的更多相关文章

  1. testng生成报告 testng-xslt 美化测试报告

    testng生成报告 testng-xslt 美化测试报告 testng生成报告 testng-xslt 美化测试报告 用TestNG测试后,自动会生成html的测试报告.利用 testNG-xslt ...

  2. 如何用 testNG 生成测试报告

    原文地址https://testerhome.com/topics/3473 总结一下testNG生成报告的三种方式,基本都是我直接转载的,没有补充就不说了,有补充的我会加以说明的(这里直说生成报告, ...

  3. ExtentReports 结合 TestNg 生成自动化 html 报告 (支持多 suite)

    转载:https://testerhome.com/topics/8134 重要说明:报告监听器源码修复一些bug,不再此处更新代码,最新代码可以到github查看最新报告监听器源码 前几天分享了ht ...

  4. TestNG+ExtentReports生成超漂亮的测试报告

    一个优雅.漂亮的测试报告,能够给我们的测试工作带来不少的加分,而报告的模版实在是让我们这些技术人员头疼的问题,设计的实在是没有什么美感. 那么今天就给大家分享一个自动化测试中,一个超漂亮的测试报告模版 ...

  5. TestNG+ExtentReports生成超漂亮的测试报告(转)

    一个优雅.漂亮的测试报告,能够给我们的测试工作带来不少的加分,而报告的模版实在是让我们这些技术人员头疼的问题,设计的实在是没有什么美感. 那么今天就给大家分享一个自动化测试中,一个超漂亮的测试报告模版 ...

  6. Testng生成的测试报告乱码解决办法

    Testng生成的测试报告乱码解决办法 2017-06-16 1 问题描述 乱码是程序编码不统一,比如Java源代码是utf-8,编译是gbk,这时会乱码. 代码如下: org.testng.Repo ...

  7. Ant中批量调用TestNG的XML文件,并调用TestNgXlst生成漂亮的html测试报告

    from:http://blog.csdn.net/bwgang/article/details/7865184 1.在Ant中设置如下: <target name="run_test ...

  8. jmeter生成报告指示板

    JMeter支持仪表板图表和报告生成 数据从一个测试计划. 这一章描述了如何配置和使用生成器. 概述 JMeter的仪表板生成器是一个模块化的扩展. 它的缺省行为是读取和处理样本 CSV文件生成HTM ...

  9. jmeter学习记录--09--命令行运行与生成报告

    一.     使用命令行方式运行Jmeter 1.1 为什么 使用GUI方式启动jmeter,运行线程较多的测试时,会造成内存和CPU的大量消耗,导致客户机卡死. 所以正确的打开方式是在GUI模式下调 ...

随机推荐

  1. C51中遇到一个有关data与xdata的问题,已解决

    环境: 我在某个C文件定义了一个结构体变量,然后该变量仅仅是在本文件内被一个函数使用,然后又在中断中调用了该函数,目的是改变一个IO口的输出状态,结果运行时怎么也达不到要的效果. struct BE ...

  2. securecrt 的安装

    http://bbs.feng.com/read-htm-tid-6939481.html ssh  -t  ip地址@用户名  -p 22

  3. 学习JQuery - 10

    第四章 Styling and Animating 1. 使用内联属性修改CSS 我们知道HTML在onload时会读取css的各项值. 那么,我们能不能在之后的操作中改变css值呢? 答案是肯定的! ...

  4. Android MemInfo 各项的意义(转)

    http://gdgzzch.blog.163.com/blog/static/37640452201371483147573/ http://stackoverflow.com/questions/ ...

  5. vux 头像上传

    参考: http://blog.csdn.net/generon/article/details/72478269

  6. js表单的focus()与blur()方法

    前段时间在多文本输入textarea中遇到点小问题,textarea在HTML是没有value属性的,但在js里的可以获取其value值. textarea禁止拉伸resize:none; (为了兼容 ...

  7. Mac - 关闭隐藏文件显示(Terminal)

    打开终端Terminal,输入:defaults write com.apple.finder AppleShowAllFiles -bool true 此命令显示隐藏文件defaults write ...

  8. netty之LengthFieldBasedFrameDecoder解码器

    官方api:http://netty.io/4.1/api/io/netty/handler/codec/LengthFieldBasedFrameDecoder.html package com.e ...

  9. log4j输出多个自定义日志文件(转)

    如果在实际应用中需要输出独立的日志文件,怎样才能把所需的内容从原有日志中分离,形成单独的日志文件呢? 先看一个常见的log4j.properties文件,它是在控制台和test.log文件中记录日志: ...

  10. OA之为用户设置角色和为用户设置权限

    1.为用户设置角色 { Layout = null; } @using OA.Model <!DOCTYPE html> <html> <head> <met ...