testng生成报告ReportNG美化测试报告
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美化测试报告的更多相关文章
- testng生成报告 testng-xslt 美化测试报告
testng生成报告 testng-xslt 美化测试报告 testng生成报告 testng-xslt 美化测试报告 用TestNG测试后,自动会生成html的测试报告.利用 testNG-xslt ...
- 如何用 testNG 生成测试报告
原文地址https://testerhome.com/topics/3473 总结一下testNG生成报告的三种方式,基本都是我直接转载的,没有补充就不说了,有补充的我会加以说明的(这里直说生成报告, ...
- ExtentReports 结合 TestNg 生成自动化 html 报告 (支持多 suite)
转载:https://testerhome.com/topics/8134 重要说明:报告监听器源码修复一些bug,不再此处更新代码,最新代码可以到github查看最新报告监听器源码 前几天分享了ht ...
- TestNG+ExtentReports生成超漂亮的测试报告
一个优雅.漂亮的测试报告,能够给我们的测试工作带来不少的加分,而报告的模版实在是让我们这些技术人员头疼的问题,设计的实在是没有什么美感. 那么今天就给大家分享一个自动化测试中,一个超漂亮的测试报告模版 ...
- TestNG+ExtentReports生成超漂亮的测试报告(转)
一个优雅.漂亮的测试报告,能够给我们的测试工作带来不少的加分,而报告的模版实在是让我们这些技术人员头疼的问题,设计的实在是没有什么美感. 那么今天就给大家分享一个自动化测试中,一个超漂亮的测试报告模版 ...
- Testng生成的测试报告乱码解决办法
Testng生成的测试报告乱码解决办法 2017-06-16 1 问题描述 乱码是程序编码不统一,比如Java源代码是utf-8,编译是gbk,这时会乱码. 代码如下: org.testng.Repo ...
- Ant中批量调用TestNG的XML文件,并调用TestNgXlst生成漂亮的html测试报告
from:http://blog.csdn.net/bwgang/article/details/7865184 1.在Ant中设置如下: <target name="run_test ...
- jmeter生成报告指示板
JMeter支持仪表板图表和报告生成 数据从一个测试计划. 这一章描述了如何配置和使用生成器. 概述 JMeter的仪表板生成器是一个模块化的扩展. 它的缺省行为是读取和处理样本 CSV文件生成HTM ...
- jmeter学习记录--09--命令行运行与生成报告
一. 使用命令行方式运行Jmeter 1.1 为什么 使用GUI方式启动jmeter,运行线程较多的测试时,会造成内存和CPU的大量消耗,导致客户机卡死. 所以正确的打开方式是在GUI模式下调 ...
随机推荐
- 管理开机启动:chkconfig
CentOS 6 如何设置服务开机启动: [root@localhost ~]$ ls /etc/init.d/httpd # /etc/init.d/目录下必须有启动脚本 [root@localho ...
- /etc/docker/key.json
/etc/docker/key.json 描述信息: This is the dockerd key for TLS connections.in web format, that docker us ...
- osgEarth2.8加载矢量数据描边效果
通过修改osgearth自带的agglite插件,实现矢量描边效果,可以自定义描边的颜色和宽度(单位像素) 测试文件osgearth_features.cpp #include <osg/Not ...
- Tomcat优化详细教程
Tomcat是我们经常使用的 servlet容器之一,甚至很多线上产品都使用 Tomcat充当服务器.而且优化后的Tomcat性能提升显著,本文从以下几方面进行分析优化. 一.内存优化 默认情况下To ...
- windows下配置VisualSVN Server服务器
下载安装文件: 服务端安装文件:VisualSVN-Server-1.6.2 客户端安装文件:TortoiseSVN-1.5.5.14361-win32-svn-1.5.4 上面是我使用的版本. 在V ...
- eclispe创建gradle项目
1.打开eclipse,选择Help——>install from Catalog,安装如图所示的gradle 2.右击空白处,new——>other——>Gradle——>G ...
- Xcode模版生成文件头部注释
在使用Xcode创建工程或者新建类的时候,顶部都会有一些xcode帮我们生成的注释 //// MySingletonClass.h// 单例模式//// Created by mark on 15/8 ...
- Thinkphp3.2 PHPexcel 导出
1 下载phpexecl 放入到tp里边. 路径如下:项目根目录\ThinkPHP\Library\Org\Util 2 PHP 代码部分 封装一个方法 private function getE ...
- java三方---->dom4j解析xml数据
Dom4j是一个易用的.开源的库,用于XML,XPath和XSLT.它应用于Java平台,采用了Java集合框架并完全支持DOM,SAX和JAXP.今天我们就开始Dom4j的学习. Dom4j的使用 ...
- 【linux系列】linux防火墙的关闭开启
即时生效 开启:service iptables start 关闭:service iptables stop 重启后生效 开启:chkconfig iptables on 关闭:chkconfig ...