您的位置:首页 > 其它

ant+TestNG-xslt生成selenium测试报告

2011-06-09 11:11 375 查看
使用 selenium+testng 做自动化测试的时候,生成的测试报告比较难看,也不是很实用。 怎样才能生成我们想要的报告呢。使用 TestNG-xslt 这个插件可以生成较理想的报告。

我们现在使用 testng 跑完测试后,会在测试代码的根目录下生成一个文件夹 test-output ,里面有 testng 生成的测试报告,也就是我们要改进的测试报告。

在 testng 生成的文件中有一个 testng-results.xml ,这里面有我们的测试结果信息。 TestNG-xslt 要做的工作就是把这个文件里面的信息重新表现。下面我们通过这 个插件来重新生成我们的测试报告。

1. 下载 TestNG-xslt 把 saxon-8.7.jar 复制到测试项目的 lib 下

2. 然后在测试项目的根目录下添加 build.xml

<project name= "myproject" basedir= "." >

<property name= "lib.dir" value= "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:/tmsTest/SeleniumTest0809/test-output/testng-results.xml" style= "D:/tmsTest/SeleniumTest0809/test-output/testng-results.xsl"

out= "D:/tmsTest/SeleniumTest0809/test-output/ index1.html " >

<!-- you need to specify the directory here again -->

<param name= "testNgXslt.outputDir" expression= "D:/tmsTest/SeleniumTest0809/test-output/" />

<classpath refid= "test.classpath" />

</xslt>

</target>

</project>

3. 从你下载的包中拷贝文件 testng-results.xsl 到 test-output 目录下。 testng-results.xsl 文件的位置是 testng-xslt-1.1.1\src\main\resources ,为什么要这个文件呢?因为我们的测试报告就是用这个 style 生成的。

4. 用 ant 运行这个 xml 就会在 test-output 目录下生成 index1.html , 打开它就能看到新生成的测试报告 , 通过生成的报告我们能看到总体的情况,比如通过了多少 case ,失败了多少,跳过了多少没执行。第二个好处是我们可以查看失败的 case 抛出的异常,有具 体的函数和行号。我们还可以通过 case 执行后的状态来过滤查询等等。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: