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.

<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 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}" />
        <antcall target="stop-server"></antcall>
    <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 name="get-jvm">
        <condition property="jvm.ok">
                     <equals arg1="${}" arg2="1.4"/>
    <target name="check_config" unless="config.ok">
        <fail message="The config file you specified does not exist" />
    <target name="start-server">
        <!-- this is a 'known location' for this -->
        <java jar="../server/selenium-server-1.0-SNAPSHOT-standalone.jar"
            <arg line="-proxyInjectionMode"/>
        <waitfor maxwait="30" maxwaitunit="second">
                 <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"/>
    <target name="stop-server">
        <get taskname="selenium-shutdown" 
            dest="result.txt" ignoreerrors="true" />
        <echo taskname="selenium-shutdown" message="DGF Errors during shutdown are expected" />

Like most things these days, I can’t claim the original work for everything involved; I just the following together:

Post a Comment

Your email is never published nor shared. Required fields are marked *