2013-07-29 260 views
2

我使用TestNG + ant +批处理文件来运行硒webddriver testscripts,但emailreport很直观,我想创建xslt。我找到了说明创建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报告,

回答

3

每件事似乎都很好,但也许你没有使用textng-xslt.xsl文件为了生成testng-xslt报告f或您的项目执行以下操作:

  1. testng-xslthere

  2. 解压下载的或可替代和TestNG的-XSLT文件夹(TestNG的-xslt- 1.1的\ src复制TestNG的-results.xsl \ main \ resources)复制到您自己的项目文件夹中。

  3. 现在从(testng-xslt-1.1 \ lib \ saxon-8.7.jar)复制撒克逊库到您的项目库文件夹。

现在使用下面的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文件并执行。