Selenium and Ant
Here is an ant file which will check a bit of environment stuff, launch the selenium server, run my tests (a custom metaframework), and then stop the server. Previously I was just running this whenever someone asked me to, but it was decided that it should be run as part of the nightly build which is controlled through ant.
<pre lang="xml"><project basedir="." default="run_test" name="Run Test">
<property name="config_file" value="c:\path\to\framework\config.xml"></property>
<available file="${config_file}" property="config.ok"></available>
<property name="test_filter" value="ro_cas"></property>
<target depends="check_jvm, check_config" description="Start Proxy ; Run Tests ; stop Proxy" name="run_test">
<antcall target="start-server"></antcall>
<exec executable="jams.bat">
<arg value="-c ${config_file}"></arg>
<arg value="${test_filter}"></arg>
</exec>
<antcall target="stop-server"></antcall>
</target>
<target depends="get-jvm" name="check_jvm" unless="jvm.ok">
<fail message="You need to use at least Java 1.5 for the selenium tests"></fail>
</target>
<target name="get-jvm">
<condition property="jvm.ok">
<not>
<or>
<equals arg1="${ant.java.version}" arg2="1.4"></equals>
</or>
</not>
</condition>
</target>
<target name="check_config" unless="config.ok">
<fail message="The config file you specified does not exist"></fail>
</target>
<target name="start-server">
<java fork="true" jar="../server/selenium-server-1.0-SNAPSHOT-standalone.jar" spawn="true">
<arg line="-proxyInjectionMode"></arg>
</java>
<waitfor maxwait="30" maxwaitunit="second">
<and>
<socket port="4444" server="localhost"></socket>
<http errorsbeginat="404" url="http://localhost:4444/selenium-server/core/index.html"></http>
</and>
</waitfor>
</target>
<target name="stop-server">
<get dest="result.txt" ignoreerrors="true" src="http://localhost:4444/selenium-server/driver/?cmd=shutDown" taskname="selenium-shutdown"></get>
<echo message="DGF Errors during shutdown are expected" taskname="selenium-shutdown"></echo>
</target>
</project>
Like most things these days, I can’t claim the original work for everything involved; I just the following together:
- Selenium RC and CI for the base outline
- Testing for the JVM version to make sure that a JVM that will run the server is in use (the product this is for is still using 1.4)
- The ant docs for all the niggly little bits