使用TestNG-xslt+ant来美化selenium测试报告

来源:互联网 发布:python sha1加密 编辑:程序博客网 时间:2024/06/05 23:58

一.背景
1.如果使用junit开发selenium测试案例,可以使用JUnit Report来生成报告
2.如果使用testNG开发selenium测试案例,不需要做额外的来产生测试报告,它会产生一个html格式的报告.
3.ReprotNG是一个testNG测试框架的插件,它可以替代默认的testNG HTML测试报告.ReprotNG提供了一个简单彩色编码测试报告试图.
4.要想获得一个非常好的总结测试报告,试一下TestNg-xslt。

二.选择TestNG-xslt生成测试报告
1,下载testng-xslt-1.1.zip
2,解压testng-xslt-1.1.zip把saxon-8.7.jar放到项目的lib目录下面,并引入到项目中
3,把testng-xslt-1.1\src\main\resources下的testng-results.xsl放到项目的src下.
4,在项目上新建test-output文件夹,并把testng-results.xsl和testng-results.xml文件放到此文件夹下.
5,在项目src下新建build.xml

<?xml version="1.0" encoding="GBK"?><project name="selenium" basedir="." default="transform">    <!-- 项目引用库文件的目录我的是C:\Users\zhangxiaoding\workspace\TestGome\Tools -->  <property name= "lib.dir" value= "D:\workspace\selenium\WebContent\WEB-INF\lib" /><path id= "test.classpath" ><!-- adding the saxon jar to your classpath --><fileset dir= "${lib.dir}" includes= "*.jar" /></path><target name= "transform" ><xslt in= "D:/workspace/selenium/test-output/testng-results.xml" style= "D:/workspace/selenium/test-output/testng-results.xsl"<!-- 生成的报告html文件的目录我的是C:/Users/zhangxiaoding/workspace/TestGome/test-output/index1.html -->out= "D:\workspace\selenium\test-output\index1.html " ><!-- you need to specify the directory here again --><!-- 下述目录同上 --><param name= "testNgXslt.outputDir" expression= "D:\workspace\selenium\test-output" /><classpath refid= "test.classpath" /></xslt></target></project>

6,最后用 ant 运行这个 xml 就会在test-output 目录下生成 index1.html,打开它就是测试报告了。

原创粉丝点击