刚刚开始学习Ant,Billy同学写的,下午仔细看了一下,并且将每个Target都独立运行了一下:
定义全局变量
<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>
启动Selenium Server
<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输出的信息可以当做是调试用的
停止Selenium Server
<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>
clean
<target name="selenium.clean">
<delete dir="${selenium.dir}/dist" failonerror="false"/>
<delete dir="${selenium.dir}/test-output" failonerror="false"/>
</target>
编译测试代码,并且Copy资源文件
<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>
用TestNG执行测试过程
<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>
Default的Target,也是最关键的部分
<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完成了.
分享到:
相关推荐
python+selenium自动化测试实例.pptx
使用Python实现Selenium自动化测试
selenium自动化基础篇.pdf
使用Python实现Selenium自动化测试
Python 24赠送课程软件测试 31-2_使用Python实现Selenium自动化测试 082.mp4
Python 24赠送课程软件测试 31-4_使用Python实现Selenium自动化测试 084.mp4
Python 24赠送课程软件测试 32-4_使用Python实现Selenium自动化测试 094.mp4
Python 24赠送课程软件测试 31-1_使用Python实现Selenium自动化测试 081.mp4
Python 24赠送课程软件测试 32-8_使用Python实现Selenium自动化测试 098.mp4
python 24、赠送课程软件测试32-7_使用Python实现Selenium自动化测试 097.mp4
python 24、赠送课程软件测试32-6_使用Python实现Selenium自动化测试 096.mp4
python 24、赠送课程软件测试32-3_使用Python实现Selenium自动化测试 093.mp4
python 24、赠送课程软件测试31-5_使用Python实现Selenium自动化测试 085.mp4
python 24、赠送课程软件测试32-1_使用Python实现Selenium自动化测试 091.mp4
python 24、赠送课程软件测试31-7_使用Python实现Selenium自动化测试 087.mp4
python 24、赠送课程软件测试31-3_使用Python实现Selenium自动化测试 083.mp4
python 24、赠送课程软件测试31-6_使用Python实现Selenium自动化测试 086.mp4
python_selenium自动化登录测试.md
软件测试丛书 Selenium自动化测试指南,欢迎下载,1111
selenium自动化进阶篇.pdf