2

我正在使用 TestNG + ant + 批处理文件来运行 selenium webddriver 测试脚本,但是 emailreport 很直观,我想创建 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 报告。,

4

1 回答 1

3

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

  1. testng-xslt或从这里下载

  2. 将 testng-results.xsl 从 testng-xslt 文件夹 (testng-xslt- 1.1\src\main\resources) 解压并复制到您自己的项目文件夹中。

  3. 现在将 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 文件并执行它。

于 2013-07-29T17:46:53.787 回答