It seems that the posts that get the most attention these days are those that deal with Selenium. I’m not sure how I feel about that, but here is another one. 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.
<project name="Run Test" default="run_test" basedir="."> <!-- sensible defaults; override as necessary --> <property name="config_file" value="c:\path\to\framework\config.xml" /> <available file="${config_file}" property="config.ok" /> <!-- see http://adam.goucher.ca/?p=21 for an explanation --> <property name="test_filter" value="ro_cas" /> <target name="run_test" depends="check_jvm, check_config" description="Start Proxy ; Run Tests ; stop Proxy"> <antcall target="start-server"></antcall> <exec executable="jams.bat" > <arg value="-c ${config_file}"/> <arg value="${test_filter}" /> </exec> <antcall target="stop-server"></antcall> </target> <target name="check_jvm" depends="get-jvm" unless="jvm.ok"> <fail message="You need to use at least Java 1.5 for the selenium tests" /> </target> <target name="get-jvm"> <condition property="jvm.ok"> <not> <or> <equals arg1="${ant.java.version}" arg2="1.4"/> </or> </not> </condition> </target> <target name="check_config" unless="config.ok"> <fail message="The config file you specified does not exist" /> </target> <target name="start-server"> <!-- this is a 'known location' for this --> <java jar="../server/selenium-server-1.0-SNAPSHOT-standalone.jar" fork="true" spawn="true"> <arg line="-proxyInjectionMode"/> </java> <waitfor maxwait="30" maxwaitunit="second"> <and> <socket server="localhost" port="4444"/> <!-- this url will 403, so we say that it should start counting errors at 404 to skip --> <http url="http://localhost:4444/selenium-server/core/index.html" errorsBeginAt="404"/> </and> </waitfor> </target> <target name="stop-server"> <get taskname="selenium-shutdown" src="http://localhost:4444/selenium-server/driver/?cmd=shutDown" dest="result.txt" ignoreerrors="true" /> <echo taskname="selenium-shutdown" message="DGF Errors during shutdown are expected" /> </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
How to stop selenium server running on specified port. i.e I use port 4446 to start selenium for our nightly build, but when we run this, looks like it doesn’t stop selenium server as it is not default port. How to pass value(4446) to stop selenium on that port. Thanks!
Note that the name of the shutDown command was changed at some point since this was posted, so in stop-server, the URL should end with ?cmd=shutDownSeleniumServer.