+ 首页>>技能>>内容

技能Selenium专题—报告生成64次围观

Selenium专题—报告生成
一般我们写的脚本可能覆盖了较多的测试项,而且可能持续运行了一段时间,本文将教各位实现在执行完自动化脚本后自动生成一份美化报告

自动生成报告类

话不多说,直接上代码,代码中会有详细注释:
程序清单1:

package ts.dw.logic;

import java.io.BufferedWriter;
import java.io.FileWriter;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.GregorianCalendar;

public class HTMLLOG {
	static GregorianCalendar time = new GregorianCalendar();	
	public static String filePath = "";
	public static String reportGenerated = "";
	
	//写入HTML
	public void generateReport()throws Exception{
	    reportGenerated="true";  
	    DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH-mm-ss");
	    Calendar cal = Calendar.getInstance();
	    String timeStamp=dateFormat.format(cal.getTime());
	    //String path = System.getProperty("user.dir")+"log";
	    filePath = "log\\"+"Regression_Result-"+"-"+timeStamp+".html";
	    FileWriter fstream = new FileWriter(filePath);
	    System.out.println("Report's FileName: "+filePath);
	    BufferedWriter out = new BufferedWriter(fstream);
	    out.write("");
	    out.write("");
	    //out.write("");
	    out.write("");
	    out.write("");

	    out.write("");
	    
	    out.write("");
	    out.write("");
	    out.write("");
	    out.write("
"); out.write(""); out.write(""); out.write(""); out.write(""); out.write("" + "" + "

自动化测试报告-By Kiven

" + "
"); /** * Creating tables in HTML for Test Status */ out.write(""); out.write(""); out.write(""); out.write(""); out.write(""); out.write(""); out.write(""); out.write(""); out.write(""); out.write(""); out.write(""); out.flush(); out.close(); } /* * 将每一步执行的情况写入日志文件 */ public void sendStatusToReport(String T_Name,String TC_ID, String Steps,String Data,String verify,String Result)throws Exception{ //先原文件末尾添加内容 FileWriter fstream = new FileWriter(filePath, true); BufferedWriter out = new BufferedWriter(fstream); //如果该行是测试用例标题行,则颜色设置为黄色,合并成一行并居中 if(Integer.parseInt(TC_ID)==0){ out.write(""); out.write(""); out.write(""); //刷新缓冲区 out.flush(); //关闭流 out.close(); }else{ //每行颜色设置成不同 //偶数行 if(Integer.parseInt(TC_ID)%2==0){ //fail if(Result.equals("Fail")){ out.write("");//红色 }else{ out.write(""); } //奇数行 }else{ //fail if(Result.equals("Fail")){ out.write("");//red:bgcolor=#FF0000 }else{ out.write("");//灰绿色 } } out.write(""); out.write(""); out.write(""); out.write(""); out.write(""); out.write(""); out.write(""); out.flush(); out.close(); } } //测试函数 public static void main(String args[]) throws Exception{ HTMLLOG hl = new HTMLLOG(); hl.generateReport(); hl.sendStatusToReport("致友登录", "0", "操作步骤", "测试数据", "预期结果", "实际结果"); hl.sendStatusToReport("", "1", "输入邮箱", "kiven@kk.com", "输入成功", "Pass"); hl.sendStatusToReport("", "2", "输入密码", "1", "输入成功", "Fail"); hl.sendStatusToReport("", "3", "输入邮箱", "kicen@kk.com", "输入成功", "Pass"); hl.sendStatusToReport("", "4", "输入密码", "1", "输入成功", "Pass"); hl.sendStatusToReport("", "5", "干什么", "1", "哦", "Pass"); } }

由测试main函数生成的报告如下:
Selenium专题—报告生成

+ 猜你喜欢...

===== 关于 DiggerPlus =====
DiggerPlus是国内新锐测试人垂直内容博客,专注于挖掘测试工具,普及测试技术,专注于测试人能力提升,博客上线后就受到广大测试人的热烈追捧;此外,DiggerPlus深度整合评测资源,揭秘科技数据和真相,让读者更懂科技,更好地把玩科技。 我们始终保持"独立,客观,严谨,优秀"的优良作风,努力为读者带来源源不断的优质内容。想访问更多酷毙的测试人网站?赶紧来DiggerPlus测试人网址导航看看吧!

===== DiggerPlus Team =====
DiggerPlus Team是DiggerPlus官方发起的团队,这是一群热爱科技,热爱测试,喜欢深度挖掘的热血测试人,他们是评测师,测试专家。 我们欢迎优秀的测试人加入DiggerPlus Team。 加入DiggerPlus,可以成为我们的认证Dper,认证Dper拥有DiggerPlus独一无二的专栏并得到个人展示。

===== DiggerPlus 官方读者群 =====
DiggerPlus官方读者群(一)

+ 关于本文作者

我也很想让世界变得更美好,可是上帝却不开放源代码。

的专栏 | 专栏作者 | 访问Kiven的主页

+ 发表评论

开源中国精彩推送

基于开源中国OpenAPI开发
  • Copyright © 2014 DiggerPlus. 91 queries in 2.162 seconds.
    使用合作网站账号快速登录,更多精彩等着您: 开源中国
    Test Case NameTest Case IDTest Name and StepsTest DataExpected ResultActual Result
    " + T_Name + "
    " + T_Name + "" + TC_ID + "" + Steps + "" + Data + "" + verify + "" + Result + "