<project name="jenkins-sample" default="ff">
    <property name="userdata.dir" value="${basedir}/userdata"/>
    <property environment="env" />
    <property name="urlbase" value="sahitest.com"/>
<taskdef name="sahi" classname="net.sf.sahi.ant.RunSahiTask" classpath="lib/ant-sahi.jar"/>
<target name="ff" description="start the server and run sahi tests">
        <parallel>
            <sequential>
                <waitfor maxwait="3" maxwaitunit="minute" checkevery="100">
                    <http url="http://localhost:9999/_s_/spr/blank.htm"/>
                </waitfor>
                <antcall target="runffandfail"/>
            </sequential>
            <antcall target="start"/>
        </parallel>
 </target>

<target name="runfftests">
        <sahi suite="../userdata/scripts/sahitests/focusTest.sah"
              browserType="firefox"
              baseurl="http://${urlbase}/demo/"
              sahihost="localhost"
              sahiport="9999"
              failureproperty="sahi.failed"
              haltonfailure="false"
              userDefinedId="sahitest.com_firefox_english"
              threads="6">
            <customfield key="language" value="english"/>
            <report type="junit" logdir="${userdata.dir}/temp/junit/tests"/>
        </sahi>
</target>

<target name="start" description="starts proxy">
        <java classname="net.sf.sahi.Proxy" fork="true">
            <classpath location="lib/sahi.jar">
                <pathelement location="extlib/rhino/js.jar"/>
                <pathelement location="extlib/apacheclient/commons-codec-1.10.jar"/>
            	<pathelement location="extlib/license/truelicense.jar"/>
            	<pathelement location="extlib/license/truexml.jar"/>
            	<pathelement location="extlib/db/h2.jar" />
				<pathelement location="extlib/poi/dom4j-2.1.3.jar"/>
				<pathelement location="extlib/poi/excelpoi.jar"/>
				<pathelement location="extlib/poi/poi.jar"/>
				<pathelement location="extlib/poi/poi-ooxml.jar"/>
				<pathelement location="extlib/poi/poi-ooxml-schemas.jar"/>
				<pathelement location="extlib/poi/xmlbeans.jar"/>
				<pathelement location="extlib/poi/commons-math3-3.6.1.jar"/>
				<pathelement location="extlib/poi/commons-compress-1.21.jar"/>
				<pathelement location="extlib/poi/commons-collections4-4.4.jar"/>
				<pathelement location="extlib/poi/SparseBitSet-1.2.jar"/>
				<pathelement location="extlib/c3p0/c3p0-0.9.5.5.jar"/>
				<pathelement location="extlib/c3p0/mchange-commons-java-0.2.20.jar"/>
                <fileset dir="extlib" includes="*.jar"/>
            </classpath>
            <arg value="." id="basePath"/>
            <arg value="userdata" id="userdataPath"/>
        </java>
</target>

<target name="stopsahi" description="stop sahi server">
        <sahi stop="true" sahihost="localhost" sahiport="9999"/>
</target>
    
<target name="failsahi" if="sahi.failed">
		<fail message="Sahi tests failed!"/>
</target>

<target name="runffandfail" depends="runfftests, stopsahi, failsahi">
</target>
	
	<target name="sahitests" description="start the server and run sahi tests">
	    <parallel>
	        <antcall target="start"/>
	        <sequential>
	            <waitfor maxwait="3" maxwaitunit="minute" checkevery="100">
	                <http url="http://localhost:9999/_s_/spr/blank.htm"/>
	            </waitfor>
	            <antcall target="runieandfail"/>
	        </sequential>
	    </parallel>
	</target>
		
	<target name="runieandfail" depends="runietests, retryfailed, stopsahi, failsahi">
	</target>

	<target name="runietests">
	    <sahi suite="${userdata.dir}/scripts/sahitests/demo.suite"
	          browserType="ie"
	          baseurl="http://sahitest.com/demo/"
	          sahihost="localhost"
	          sahiport="9999"
	          failureproperty="sahi.failed"
	          haltonfailure="false"
	    		userDefinedId="sahitest.com_english"
	          threads="6"
	            >
	    	<customfield key="language" value="english"/>
	        <report type="html" logdir="${userdata.dir}/temp/html/tests"/>
	    </sahi>
	</target>
		
	<target name="retryfailed" if="sahi.failed">
	    <sahi suite="${userdata.dir}/scripts/sahitests/demo_failed_ie.suite"
	      	  browserType="ie"
	          baseurl="http://sahitest.com/demo/"
	          sahihost="localhost"
	          sahiport="9999"
	          failureproperty="sahi.failed"
	          haltonfailure="false"
	      	  userDefinedId="sahitest.com_english"
			  threads="1">
	  		<customfield key="language" value="english"/>
	    	<report type="html" logdir="${userdata.dir}/temp/html/tests/retry/"/>
	    </sahi>		
	</target>
</project>
