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模式下调 ...
随机推荐
- 换个思路理解Javascript中的this
https://segmentfault.com/a/1190000010328752
- HTTP 错误 404.3 解决
问题 由于扩展配置问题而无法提供您请求的页面.如果该页面是脚本,请添加处理程序.如果应下载文件,请添加 MIME 映射. 解决 在开始菜单中找到 Visual Studio 命令提示工具.然后用管理员 ...
- mybatis由浅入深day01_9动态sql(9.5sql片段_9.6foreach)
9 动态sql 9.1 什么是动态sql mybatis核心 对sql语句进行灵活操作,通过表达式进行判断,对sql进行灵活拼接.组装. 9.2 需求 用户信息综合查询列表和用户信息查询列表总数这两个 ...
- Effective C++ Item 13 Use object to manage resources
1. Always use object to manage resource! If you delete a pointer or release a handler manually by yo ...
- Mac下,如何把Github上的仓库删除掉
这个虽然简单,但是还是做个记录,当初也是找不到地方,最终还是去百度了,步骤很简单: 如下: 1.进入Github主页,选中你要删除的仓库,点击进入到如下页面:
- 转的:burp suite小例子
Web安全测试时经常会遇到一些蹩脚的注射点,而因各种原因利用注射又无法获取网站管理账号或拥有网站管理权限却迟迟不能upload一个shell的时候,可能会权衡一下web权限与数据库信息,哪个是我们所需 ...
- 更改嵌入式Linux中开机画面----左上角小企鹅图标
一直想给嵌入式仪表加个开机LOGO,但是没有找到更换的方法.最近在网上收集了一些文章,整理一下一共自己参考.目前也还没有试过这种方法究竟是否可以.但察看Kernel源代码可以知道,Linux-2.6的 ...
- Spring学习笔记--声明一个简单的Bean
spring依赖的maven dependencyhttp://mvnrepository.com/artifact/org.springframework 在pom.xml中添加如下依赖: < ...
- LeetCode——pow(x, n)
超时了,只能先这么干了. return Math.pow(x, n);
- postgresql数据库中对重复数据的处理
我们在使用postgresql数据库的时候,如果一张数据表在未做任何约束的情况下,很可能会出现几条完全一样的数据,即重复数据.如下图所示: 那么如果我们要删除其中的2条该怎么办呢?第一种我们可以清空表 ...