当预期在项目文件夹中时,在桌面上生成TestNG测试输出文件夹

时间:2013-06-13 11:01:50

标签: ant webdriver testng

我在自动化项目中设置了 Selenium WebDriver + TestNG + Ant框架。几个月前,使用build.xml从Ant运行webdriver + TestNG测试工作得非常好。 TestNG按预期在项目目录中生成test-output文件夹。

现在,当我从ANT运行我的testng测试时,它会在我的桌面(home / user / Desktop)上生成默认的报告文件夹test-output。我不知道为什么会这样。

这是我的build.xml文件:

<project name="InitialConfigProject" default="start" basedir=".">  
<!-- ========== Initialize Properties =================================== -->
<property environment="env"/>
<property file="./app.properties"/>

<property name="ws.home" value="${basedir}"/>
<property name="test.dest" value="${ws.home}/build"/>
<property name="test.src" value="${ws.home}/src"/>
<property name="browser" value="/usr/bin/google-chrome"/>
<property name="mail_body_file" value="${basedir}/email_body.txt"/>
<property name="buildID" value="IND3.2.0"/>
<property name="sendmailscript_path" value="${basedir}/sendmail.sh"/>
<property name="mail_subject" value="Automated_test_execution_of_${buildID}"/>


<!-- ====== Set the classpath ====  -->
<target name="setClassPath" unless="test.classpath">

    <path id="classpath_jars">
        <fileset dir="${ws.home}/lib" includes="*.jar"/>
    </path>
    <pathconvert pathsep=":" property="test.classpath" refid="classpath_jars"/>

</target>




<!-- ============ Initializing other stuff ===========  -->
<target name="init" depends="setClassPath">

    <tstamp>
        <format property="timestamp" pattern="dd/MM/yyyy hh:mm aa" />
    </tstamp>
    <!--
    <condition property="ANT" 
        value="${env.ANT_HOME}/bin/ant.bat" 
        else="${env.ANT_HOME}/bin/ant">
                <os family="windows" />
    </condition> -->
    <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}"/>
    <echo message="Loading TestNG.." />
    <taskdef name="testng" classpath="${test.classpath}" classname="org.testng.TestNGAntTask" />

</target>



<!-- cleaning the destination folders -->
<target name="clean">
    <delete dir="${test.dest}"/>
</target>


<!-- compiling files -->
<target name="compile" depends="init, clean" > 
    <delete includeemptydirs="true" quiet="true">
        <fileset dir="${test.dest}" includes="**/*"/>
    </delete>
    <echo message="making directory..."/>
    <mkdir dir="${test.dest}"/>

    <copy file="${ws.home}/app.properties" todir="${ws.home}/build" />
    <copy file="${ws.home}/resources/testdata/testDataSet1.properties" todir="${ws.home}/build" />
    <echo message="compiling source files..."/>
    <javac 
        debug="true" 
        destdir="${test.dest}" 
        srcdir="${test.src}" 
        target="1.6" 
        classpath="${test.classpath}"
        includeantruntime="true"
    >
    </javac>
  </target>



<!-- run -->
<target name="run" depends="compile">
    <testng outputdir="${ws.home}/test-output" classpath="${test.classpath}:${test.dest}" suitename="Praxify Sanity Suite">
       <xmlfileset dir="${ws.home}" includes="testng.xml"/> 
    </testng>
</target>



<!--  ========== Generating reports using XSLT utility ==============    -->
<target name="testng-xslt-report">
        <delete dir="${basedir}/testng-xslt">
        </delete>
        <mkdir dir="${basedir}/testng-xslt">
        </mkdir>
        <xslt in="${basedir}/test-output/testng-results.xml" style="${basedir}/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,CONF,BY_CLASS" name="testNgXslt.testDetailsFilter" />
            <param expression="true" name="testNgXslt.showRuntimeTotals" />
            <classpath refid="classpath_jars"></classpath>
        </xslt>
</target>


<!-- Starting point of the execution, should be dependent on target "run".

Target sequence will be:
start (not_execute) ==> run (not_execute) ==> compile (not_execute) ==> init (execute) ==> clean (execute)
start (execute) <== testng-xslt-report (execute) <== run (execute) <== compile (execute) <==

Suitable for ANT 1.7. Currently using this ====================== -->


<target name="start" depends="run, testng-xslt-report">
    <tstamp prefix="getTime">
            <format property="TODAY" pattern="MM-dd-yyyyhhmmaa"/>
    </tstamp>
    <echo message="sending report as mail...."/>
    <property name="execution_time" value="${buildID}_${getTime.TODAY}"/>
    <property name="dest_file" value="/home/xtremum/Reports/${execution_time}.zip"/>
    <zip destfile="/home/xtremum/Reports/${execution_time}.zip" basedir="${basedir}/testng-xslt"/>
    <property name="report_attachment_file" value="${dest_file}"/>
    <exec executable="${sendmailscript_path}" newenvironment="false"> 
                <arg value="${mail_subject}"/>
                <arg value="${mail_recipient}"/>
                <arg value="${report_attachment_file}"/>
                <arg value="${mail_body_file}"/> 
    </exec>
 </target>


仅供记录:
1.我正在使用Eclipse Juno 2.我在Eclipse上安装了TestNG插件,以便我可以直接从eclipse运行测试,方法是右键单击testng.xml并运行Run。 3.我在我的Ubuntu机器上安装了ANT 1.7,并将我的ANT_HOME设置为/ usr / share / ant。我在Windows中查找 - &gt;偏好 - &gt;蚂蚁 - &gt;运行时 - &gt; Ant Home Entries(默认)它们似乎引用了Eclipse包中的ant 1.8.3库(JARS)(eclipse / plugins /)。这里有什么不对吗?
4.我通过eclipse运行测试而不是命令行。

我没有收到任何构建错误。测试正在执行,但test-output文件夹正在桌面上创建。有什么帮助吗?

1 个答案:

答案 0 :(得分:0)

如果您正在运行testng插件选项,则输出文件夹将是您在Project-&gt; Properties-&gt; TestNG-&gt; OutputDirectory

中指定的文件夹