Selenium自动化测试的Build.xml例子

刚刚开始学习Ant,Billy同学写的,下午仔细看了一下,并且将每个Target都独立运行了一下:

[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完成了.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值