刚刚开始学习Ant,Billy同学写的,下午仔细看了一下,并且将每个Target都独立运行了一下:
[color=red][*]定义全局变量[/color]
[color=red][*]启动Selenium Server[/color]
echo输出的信息可以当做是调试用的
[color=red][*]停止Selenium Server[/color]
[color=red][*]clean[/color]
[color=red][*]编译测试代码,并且Copy资源文件[/color]
[color=red][*]用TestNG执行测试过程[/color]
[color=red][*]Default的Target,也是最关键的部分[/color]
最后,在项目的根节点加入Default target:
这样一个Build.xml完成了.
[color=red][*]定义全局变量[/color]
<property name="selenium.dir" value="../MatrixAutomatedTesting-Trunk/" />
<property name="selenium.src.dir" value="${selenium.dir}" />
<property name="selenium.dist.dir" value="${selenium.dir}/dist" />
<property name="selenium.lib.dir" value="${selenium.dir}/lib" />
<property name="selenium.suite.dir" value="${selenium.dir}" />
<path id="selenium.classpath.main">
<pathelement location="." />
<pathelement location="${selenium.dist.dir}" />
<fileset dir="${selenium.lib.dir}/">
<include name="**/*.jar" />
</fileset>
</path>
[color=red][*]启动Selenium Server[/color]
<target name="start_selenium_server">
<echo message="starting selenium server" />
<java jar="${selenium.lib.dir}/selenium-server.jar" fork="true" spawn="false" output="selenium.log">
<arg line="-port 4444" />
</java>
</target>
echo输出的信息可以当做是调试用的
[color=red][*]停止Selenium Server[/color]
<target name="stop_selenium_server">
<echo message="going to stop the selenium server" />
<get taskname="selenium-shutdown" src="http://localhost:4444/selenium-server/driver/?cmd=shutDownSeleniumServer" dest="stop.out" ignoreerrors="true" />
</target>
[color=red][*]clean[/color]
<target name="selenium.clean">
<delete dir="${selenium.dir}/dist" failonerror="false"/>
<delete dir="${selenium.dir}/test-output" failonerror="false"/>
</target>
[color=red][*]编译测试代码,并且Copy资源文件[/color]
<target name="selenium.compile">
<echo message="starting to compile the classess" />
<!--clean the old classes-->
<delete dir="${selenium.dist.dir}" failonerror="false" />
<!--create new dist dir-->
<mkdir dir="${selenium.dist.dir}/com/perficient/properties/" />
<!--compile-->
<javac classpathref="selenium.classpath.main" srcdir="${selenium.src.dir}" destdir="${selenium.dist.dir}" />
<copy todir="${selenium.dist.dir}/com/perficient/properties/">
<fileset dir="${selenium.src.dir}/src/com/perficient/properties/" />
</copy>
<copyfile dest="${selenium.dist.dir}/log4j.properties" src="${selenium.src.dir}/src/log4j.properties" />
</target>
[color=red][*]用TestNG执行测试过程[/color]
<taskdef resource="testngtasks" classpath="${selenium.lib.dir}/testng-jdk15.jar" />
<target name="selenium.test">
<testng classpathref="selenium.classpath.main" failureproperty="test.failed">
<jvmarg value="-Dselenium.port=4444" />
<!--xml test suite file -->
<xmlfileset dir="${selenium.suite.dir}">
<include name="MatrixSuite.xml" />
</xmlfileset>
</testng>
<antcall target="stop_selenium_server" />
</target>
[color=red][*]Default的Target,也是最关键的部分[/color]
<target name="start_server_and_run_tests" depends="selenium.clean, selenium.compile" description="start selenium server and run tests">
<parallel>
<antcall target="start_selenium_server" />
<sequential>
<echo taskname="waitfor" message="wait for selenium server launch" />
<waitfor maxwait="2" maxwaitunit="minute" checkevery="10">
<http url="http://localhost:4444/selenium-server/driver/?cmd=testComplete" />
</waitfor>
<antcall target="selenium.test">
</antcall>
</sequential>
</parallel>
</target>
最后,在项目的根节点加入Default target:
<project name="selenium automation" default="start_server_and_run_tests" basedir=".">
这样一个Build.xml完成了.