我正在使用TestNG + ant +批处理文件来运行selenium webddriver测试脚本,但是电子邮件报告很直观,我想创建xslt。我找到了教程,其中说创建没有批处理运行文件的xslt报告。但我也需要批处理文件。
这里我粘贴了我的build.xml文件
<project name="Planobot_Final" default="run" basedir=".">
<property name="source" value="./src" />
<property name="lib" value="./Lib" />
<property name="build_root" value="./Maheswar/" />
<property name="build_child" value="${build_root}/Test-Data" />
<property name="dist_dir" value="./dist" />
<property name="jar_name" value="Planobot.jar" />
<property name="testng_output.dir" value="${basedir}/testng_output" />
<!-- Clean -->
<target name="clean">
<delete dir="${build_root}" />
<delete dir="${build_child}" />
<delete dir="${dist_dir}" />
<delete dir="${basedir}/testng-xslt" />
<delete dir="${testng_output.dir}" />
</target>
<!-- Init -->
<target name="init">
<mkdir dir="${build_root}" />
<mkdir dir="${build_child}" />
<mkdir dir="${dist_dir}" />
<mkdir dir="${basedir}/testng-xslt" />
<mkdir dir="${testng_output.dir}" />
</target>
<!-- Compile -->
<target name="compile">
<javac srcdir="${source}" destdir="${dist_dir}">
<classpath>
<fileset dir="${lib}">
<include name="**/*.jar" />
</fileset>
</classpath>
</javac>
</target>
<!-- Default -->
<target name="run">
<antcall target="clean" />
<antcall target="init" />
<antcall target="compile" />
<antcall target="jar" />
<antcall target="deploy" />
</target>
<!-- Jar -->
<target name="jar">
<jar destfile="${build_root}/${jar_name}" basedir="${dist_dir}">
<manifest>
<attribute name="Main-Class" value="org.testng.TestNG" />
<attribute name="Class-Path" value="/lib/*.*" />
<attribute name="Implementation-Version" value="6.6beta-201206151641" />
</manifest>
<fileset dir="${dist_dir}" />
<fileset file="${basedir}\testng.xml" />
</jar>
</target>
<!-- Deploy -->
<target name="deploy">
<copydir dest="${build_child}" src="${basedir}/Test-Data" />
<copydir dest="${build_root}/lib" src="${basedir}/Lib">
</copydir>
<!--<copyfile dest="${build_root}/lib" src="${build_root}/${jar_name}"/> -->
<copy file="${build_root}/${jar_name}" todir="${build_root}/lib">
</copy>
<copy file="./Final.bat" todir="${build_root}">
</copy>
<copy file="./testng.xml" todir="${build_root}">
</copy>
</target>
<target name="xslt" depends="run">
<xslt in="${basedir}/testng_output/testng-results.xml" style="${basedir}/testng-results.xsl" out="${basedir}/testng-xslt/index.html">
<param expression="${basedir}/testng-xslt/" name="testNgXslt.outputDir" />
<param expression="true" name="testNgXslt.sortTestCaseLinks" />
<param expression="FAIL,SKIP,PASS,CONF,BY_CLASS" name="testNgXslt.testDetailsFilter" />
<param expression="true" name="testNgXslt.showRuntimeTotals" />
<classpath refid="master-classpath">
</classpath>
</xslt>
</target>
以及final.bat文件
echo Setting JAVA_HOME
set JAVA_HOME="C:\\Java\\jdk1.7.0"
echo setting PATH
set PATH="C:\\Java\\jdk1.7.0";%PATH%
echo Display java version
set BASELIBS="D:\\Planobot-KHFW\\Planobot_Test\\Maheswar\\lib"
::This is the planobotlog properties file.
::set JAVA_OPTIONS=-DconfDir=D:\Planobot-KHFW\Planobot_Test\Maheswar\Test-Data\Property
::set PropertyDirectory = "D:\\Planobot-KHFW\\Planobot_Test\\${app_root_dir}\\testArea\\Test-Data\\Property"
::Before running the batch delete the hardcodded value of confDir in all the testcases
::set JAVA_OPTIONS=PropDir=D:\Planobot-KHFW\Planobot_Test\${app_root_dir}\testArea\Test-Data\Property
`set CLASS_PATH=%BASELIBS%\\dom4j-1.6.1.jar;%BASELIBS%\\JSErrorCollector-0.4.jar;%BASELIBS%\\jxl.jar;%BASELIBS%\\log4j-1.2.14.jar;%BASELIBS%\\maven-eclipse-plugin-2.2.jar;%BASELIBS%\\poi-3.0.2-FINAL.jar;%BASELIBS%\\poi-3.9-20121203.jar;%BASELIBS%\\poi-examples-3.9-20121203.jar;%BASELIBS%\\poi-excelant-3.9-20121203.jar;%BASELIBS%\\poi-ooxml-3.9-20121203.jar;%BASELIBS%\\poi-ooxml-schemas-3.9-20121203.jar;%BASELIBS%\\poi-scratchpad-3.9-20121203.jar;%BASELIBS%\\saxon-8.7.jar;%BASELIBS%\\selenium-java-2.33.0.zip;%BASELIBS%\\selenium-server-standalone-2.33.0.jar;%BASELIBS%\\testng.jar;%BASELIBS%\\xmlbeans-2.3.0.jar;%BASELIBS%\\Planobot.jar;`
echo %BASELIBS%\\dom4j-1.6.1.jar
java -cp %CLASS_PATH% %JAVA_OPTIONS% org.testng.TestNG -testjar %BASELIBS%\\Planobot.jar -xmlpathinjar testng.xml
ant makexsltreports
@pause
但是我无法获得xslt报告。
答案 0 :(得分:3)
每件事似乎都很好,但也许您没有使用过textng-xslt.xsl文件为了为您的项目生成testng-xslt报告,请执行以下操作:
从testng-xslt或here下载
将testng-results.xsl从testng-xslt文件夹(testng-xslt-1.1 \ src \ main \ resources)解压缩并复制到您自己的项目文件夹中。
现在将saxon库从(testng-xslt-1.1 \ lib \ saxon-8.7.jar)复制到项目lib文件夹。
现在使用以下build.xml(我已尝试按照您的要求进行更新,但如果需要进行一些更改,请自行执行)
<project name="Planobot_Final" basedir=".">
<property name="home.dir" value="${basedir}"/>
<property name="build.dir" value="${home.dir}/build"/>
<property name="src.dir" value="${home.dir}/src"/>
<property name="ng.result" value="test-output"/>
<property name="lib.dir" value="./Lib"/>
<property name="browser" value="C:\Program Files \Mozilla Firefox\firefox"/>
<property name="index.dir" value = "${basedir}/testng_output/index.html"/>
<!-- setClassPath -->
<target name="setClassPath">
<path id="classpath_jars">
<pathelement path="${basedir}/" />
<fileset dir="${lib.dir}" includes="*.jar" />
</path>
<pathconvert pathsep=":" property="test.classpath" refid="classpath_jars" />
</target>
<!-- loadTestNG -->
<target name="loadTestNG" depends="setClassPath">
<taskdef resource="testngtasks" classpath="${test.classpath}"/>
</target>
<!-- build -->
<target name="build">
<mkdir dir="${build.dir}"/>
<tstamp>
<format property="timestamp" pattern="dd-MM-yyyy_(HH-mm-ss)"/>
</tstamp>
<property name="build.log.dir" location="${basedir}/buildlogs"/>
<mkdir dir="${build.log.dir}"/>
<property name="build.log.filename" value="build_${timestamp}.log"/>
<record name="${build.log.dir}/${build.log.filename}" loglevel="verbose" append="false"/>
<echo message="build logged to ${build.log.filename}"/>
</target>
<!-- Clean -->
<target name="clean">
<echo message="deleting existing build directory"/>
<delete dir="${build.dir}"/>
</target>
<!-- Compile -->
<target name="compile" depends="clean,build,setClassPath,loadTestNG">
<echo message="classpath:${test.classpath}"/>
<echo message="compiling.........."/>
<javac destdir="${build.dir}" srcdir="${src.dir}" classpath="${test.classpath}"/>
</target>
<!-- executeApp -->
<target name="executeApp" depends="compile">
<testng classpath="${test.classpath}:${build.dir}">
<xmlfileset dir="${basedir}" includes="testng.xml"/>
</testng>
</target>
<!-- Report -->
<target name="report" depends="executeApp">
<delete dir="${basedir}/testng-xslt"/>
<mkdir dir="${basedir}/testng-xslt"/>
<xslt in="${basedir}/test-output/testng-results.xml"
style="${basedir}/src/xslt/testng-results.xsl" out="${basedir}/testng-xslt/index.html" processor="SaxonLiaison">
<param expression="${basedir}/testng-xslt/" name="testNgXslt.outputDir"/>
<param expression="true" name="testNGXslt.sortTestCaseLinks"/>
<param expression="FAIL,SKIP,PASS,BY_CLASS" name="testNgXslt.testDetailsFilter"/>
<param expression="true" name="testNgXslt.showRuntimeTotals"/>
<classpath refid="classpath_jars"/>
</xslt>
</target>
<!-- makexsltreports-->
<target name="makexsltreports" depends="report">
<exec executable="${browser}" spawn="yes">
<arg line="${index.dir}" />
</exec>
</target>
</project>
现在使用相同的bat文件并执行它。