工具:Eclipse、Testng、Reportng、Ant
場(chǎng)景:通過(guò)Ant執(zhí)行Testng用例,并輸出Reportng報(bào)告
1、編寫(xiě)ant腳本
<?xml version="1.0"?>
<project name="MySelenium" default="run" basedir=".">
<echo message="import libs" />
<echo>Java-Home: ${java.home}</echo>
<echo>Java-Version: ${java.version}</echo>
<property name="src.dir" value="src est" />
<property name="dest.dir" value="build" />
<property name="dest.report" value="report" />
<path id="run.classpath">
<fileset dir="${basedir}">
<include name="lib/*.jar" />
</fileset>
</path>
<taskdef name="testng" classname="com.beust.testng.TestNGAntTask">
<classpath>
<pathelement location="lib/testng-6.9.9.jar"/>
</classpath>
</taskdef>
<target name="clean">
<delete dir="${dest.dir}" />
</target>
<target name="compile" depends="clean">
<echo message="mkdir" />
<mkdir dir="${dest.dir}" />
<javac target="1.7" srcdir="${src.dir}" destdir="${dest.dir}" encoding="UTF-8" debug="on" includeAntRuntime="false" >
<classpath refid="run.classpath" />
</javac>
</target>
<path id="runpath">
<path refid="run.classpath" />
<pathelement location="${dest.dir}" />
</path>
<target name="run" depends="compile">
<testng classpathref="runpath" outputDir="${dest.report}" haltOnFailure="true" useDefaultListeners="false" listeners="org.uncommons.reportng.HTMLReporter,org.uncommons.reportng.JUnitXMLReporter,org.testng.reporters.FailedReporter">
<!--<testng classpathref="runpath" outputDir="${dest.report}" haltOnFailure="true" useDefaultListeners="true" >-->
<xmlfileset dir="${basedir}" includes="testng.xml" />
<jvmarg value="-ea" />
</testng>
</target>
</project>
2、引入需要的jar包
testng輸出報(bào)告
好將下面的jar包都引入,不然會(huì)瘋掉的,會(huì)一個(gè)個(gè)報(bào)錯(cuò)提示你
(其中jxl-2.6.12.jar讀取excel,東面j-1.6.jar讀取xml,沒(méi)有用到的可以不加)