Monday 5 July 2010

Use marathon ant and maven

Running marathon from an ant task is easy. To setup the classpath however is a pain. Marathon can either run in test or gui mode. Gui is used when you develop a test.

Start with installing the actual marathon application.

Create a pom with the artifact that contains the gui application. This is just so that the pom version is updated by a release.

Finally use this ant file to run marathon:
-------------------------------------------------------
<?xml version="1.0"?>

<project name="main" basedir="." xmlns:artifact="antlib:org.apache.maven.artifact.ant">


<property name="m2_loc_repo" value="${user.home}/.m2/repository"/>

<!-- has its own pom so that we the version will change with the maven releases -->
<artifact:dependencies pathId="aqva_client.classpathId">
<pom file="pom.xml"/>
<localRepository path="${m2_loc_repo}"/>
</artifact:dependencies>

<taskdef resource="net/sf/antcontrib/antlib.xml"/>

<property file="aqva_marathon.properties"/>
<fail unless="marathon.home">
You need to add a file called aqva_marathon.properties with the following properties:

marathon.home (required): path to marathon downloaded from here http://www.marathontesting.com
aqva_url (optional): url to aqva server, default: http://localhost:8080/Aqva/
aqva_user (optional): user aqva server, default: roger
aqva_pwd (optional): password aqva server, default: helly
</fail>


<path id='marathon_classpath'>
<fileset dir="${marathon.home}">
<include name="marathon.jar"/>
<include name="marathon-python.jar"/>
<include name="marathon-ruby.jar"/>
<include name="marathon-runtime.jar"/>
</fileset>
<fileset dir="${marathon.home}/Support">
<include name="forms-1.2.1/forms-1.2.1.jar"/>
<include name="jaccess-1.3/jaccess.jar"/>
<include name="jedit-textArea.jar"/>
<include name="jline-0.9.93.jar"/>
<include name="junit3.8.2/junit.jar"/>
<include name="looks-2.2.0/looks-2.2.0.jar"/>
<include name="vldocking_2.1.5C.jar"/>
</fileset>
</path>


<property name='marathon.project.dir' value='.'/>

<!-- the default test i.e. all tests -->
<property name="test" value=""/>
<property name="aqva_url" value="xxx"/>
<property name="aqva_user" value="yyy"/>
<property name="aqva_pwd" value="zzz"/>

<!-- has a value that is used for all tests in run, use this to create unique data that is used
between tests in one run -->
<tstamp>
<format property="timestamp_val" pattern="yyyyMMdd_HHmmss_SSS" />
</tstamp>


<target name="test" description="runs test(s) in batch mode (wo gui) -Dtest= to run a specific test">
<property name="app_classpath" refid="aqva_client.classpathId"/>

<java classname="net.sourceforge.marathon.Main" fork="yes">
<classpath refid="marathon_classpath"/>
<jvmarg value="-Dmarathon.application.classpath=${app_classpath}"/>
<jvmarg value="-Dpython.cachedir=${env.HOME}/.jycache"/>
<jvmarg value="-Dmarathon.project.file=marathon_test.project"/>
<!-- send in java exe -->
<jvmarg value="-Dmarathon.application.vm.command=${java.home}/bin/java"/>
<!-- send startup args -->
<jvmarg value="-Dmarathon.application.vm.arguments=-Daqva_url=${aqva_url} -Daqva_user=${aqva_user} -Daqva_pwd=${aqva_pwd} -Dtimestamp_val=${timestamp_val}"/>

<arg value="-batch"/>
<arg value="-reportdir"/>
<arg value="${marathon.project.dir}/reports"/>
<arg line="${marathon.project.dir}"/>
<arg line="${test}"/>
</java>
</target>

<target name="gui" description="run marathon gui for developing tests">
<!-- need to set the classpath in the project file-->
<property name="app_classpath" refid="aqva_client.classpathId"/>

<propertyregex property="app_classpath_fixed"
input="${app_classpath}"
regexp="\\"
replace="/"
global="true"
defaultValue="${app_classpath}"/>
<propertyregex property="JAVA_EXE_PATH_fixed"
input="${java.home}/bin/java"
regexp="\\"
replace="/"
global="true"
defaultValue="${java.home}/bin/java"/>
<copy file="resources/marathon_gui.project_TEMPLATE" tofile="temp/marathon_gui.project" overwrite="true">
<filterset>
<filter token="APP_CLASSPATH" value="${app_classpath_fixed}"/>
<filter token="JAVA_EXE_PATH" value="${JAVA_EXE_PATH_fixed}"/>
<filter token="APP_ARGS"
value="-Daqva_url=${aqva_url} -Daqva_user=${aqva_user} -Daqva_pwd=${aqva_pwd} -Dtimestamp_val=${timestamp_val}"/>
</filterset>
</copy>

<!--echo message="${app_classpath}"/-->
<java classname="net.sourceforge.marathon.Main" fork="yes">
<classpath refid="marathon_classpath"/>
<jvmarg value="-Xmx256m"/>
<jvmarg value="-Dmarathon.home=${marathon.home}"/>
<jvmarg value="-Dpython.cachedir=${env.HOME}/.jycache"/>
<jvmarg value="-Dmarathon.project.file=temp/marathon_gui.project"/>

<arg line="${marathon.project.dir}"/>
</java>
</target>

</project>

------

No comments: