Wednesday, July 17, 2013

JMeter ANT Build



I have some steps config before run Ant build such as:

1.      -     Download Ant [ant-jmeter-1.1.1.jar] into link: D:\apache-jmeter-2.9\extras.
      -  Download [jmeter-results-detail-report_21.xsl] into link: D:\apache-jmeter-2.9\extras.
2.       Set classpath in Window7:
set JAVA_HOME=C:\bea102\jdk150_11
set JMETER_HOME= D:\apache-jmeter-2.9
set ANT_HOME= C:\apache-ant-1.7.1
set PATH=%JAVA_HOME%\bin;%ANT_HOME%\bin;%PATH%
set CLASSPATH=%JMETER_HOME%\extras\ ant-jmeter-1.1.1.jar;%CLASSPATH%
ant %*

3.  Modify something in build.xml in link: D:\apache-jmeter-2.9\extras


<?xml version="1.0"?>

<project name="ant-jmeter" basedir="." default="all">
    <description>
  
        Sample build file for use with ant-jmeter.jar
        See http://www.programmerplanet.org/pages/projects/jmeter-ant-task.php
      
    To run a test and create the output report:
        ant -Dtest=script
  
    To run a test only:
        ant -Dtest=script run
      
    To run report on existing test output
        ant -Dtest=script report
  
    The "script" parameter is the name of the script without the .jmx suffix.
  
    Additional options:
        -Dshow-data=y - include response data in Failure Details
        -Dtestpath=xyz - path to test file(s) (default user.dir).
                         N.B. Ant interprets relative paths against the build file
        -Djmeter.home=.. - path to JMeter home directory (defaults to parent of this build file)
        -Dreport.title="My Report" - title for html report (default is 'Load Test Results')

        Deprecated:
        -Dformat=2.0 - use version 2.0 JTL files rather than 2.1

    </description>
  
   
    <property name="testpath" value="D:/ProjectName/"/>
    <property name="jmeter.home" value="${basedir}/.."/>
    <property name="jmeter-home" value="${basedir}/.."/>
    <property name="report.title" value="Load Test Results"/>
    <property name="request.threads" value="1"/>
    <property name="request.loop" value="10"/>
  
    <!-- Results -->  
    <property name="jtlpath" value="${testpath}/results"/>
    <!-- Scripts -->  
    <property name="scriptpath" value="${testpath}/scripts/"/>
    <!-- Conf -->  
    <property name="confpath" value="${testpath}/conf"/>
    <!--CSV file-->
    <property name="LoginData" value="${confpath}/User_Standard.csv"/>
    <property name="ProjectData" value="${confpath}/User_Standard_P.csv"/>
    <property name="TrackerData" value="${confpath}/User_Standard_T.csv"/>
    <property name="Applicationdata" value="${confpath}/Application.csv"/>
  
    <!-- Name of test (without .jmx) -->
    <property name="test" value="Test"/>
  
    <!-- Should report include response data for failures? -->
    <property name="show-data" value="n"/>

    <property name="format" value="2.1"/>
      
    <condition property="style_version" value="">
        <equals arg1="${format}" arg2="2.0"/>
    </condition>

    <condition property="style_version" value="_21">
        <equals arg1="${format}" arg2="2.1"/>
    </condition>

    <condition property="funcMode">
        <equals arg1="${show-data}" arg2="y"/>
    </condition>
  
    <condition property="funcMode" value="false">
      <not>
        <equals arg1="${show-data}" arg2="y"/>
      </not>
    </condition>

    <!-- Allow jar to be picked up locally -->
  
    <!-- ant-jmeter.jar comes with jmeter, be sure this is the release you have -->
      <path id="ant.jmeter.classpath">
        <pathelement
           location="${jmeter-home}/extras/ant-jmeter-1.1.1.jar" />
            <fileset dir="${basedir}">
            <include name="ant-jmeter*.jar"/>
        </fileset>
      </path>


       <taskdef
        name="jmeter"
        classpathref="ant.jmeter.classpath"
        classname="org.programmerplanet.ant.taskdefs.jmeter.JMeterTask"
    />
  
    <target name="all" depends="run,report"/>

    <target name="run">
        <echo>funcMode = ${funcMode}</echo>
        <delete file="${jtlpath}/*.html"/>
        <jmeter
            jmeterproperties="${confpath}/Merge_Timesheet_Resource_Report.properties"
            jmeterhome="D:/apache-jmeter-2.9"          
            resultlog="${jtlpath}/Coconet_Timesheet_server_resource.jtl">
            <testplans dir="${scriptpath}" includes="*.jmx"/>
          
      
            <!-- Force suitable defaults -->
            <property name="jmeter.save.saveservice.output_format" value="xml"/>
            <property name="jmeter.save.saveservice.assertion_results" value="all"/>
            <property name="jmeter.save.saveservice.bytes" value="true"/>
            <property name="file_format.testlog" value="${format}"/>
            <property name="jmeter.save.saveservice.response_data.on_error" value="${funcMode}"/>
          
            <property name="jmeter.save.saveservice.response_data" value="true"/>
            <property name="jmeter.save.saveservice.samplerData" value="true"/>
            <property name="jmeter.save.saveservice.responseHeaders" value="true"/>
            <property name="jmeter.save.saveservice.requestHeaders" value="true"/>
            <property name="jmeter.save.saveservice.encoding" value="true"/>
            <property name="jmeter.save.saveservice.url" value="true"/>
            <property name="jmeter.save.saveservice.filename" value="true"/>
            <property name="jmeter.save.saveservice.hostname" value="true"/>
            <property name="jmeter.save.saveservice.thread_counts" value="true"/>
            <property name="jmeter.save.saveservice.sample_count" value="true"/>
            <property name="jmeter.save.saveservice.idle_time" value="true"/>          
          
        </jmeter>
    </target>

    <property name="lib.dir" value="${jmeter.home}/lib"/>
  
    <!-- Use xalan copy from JMeter lib directory to ensure consistent processing with Java 1.4+ -->
    <path id="xslt.classpath">
        <fileset dir="${lib.dir}" includes="xalan*.jar"/>
        <fileset dir="${lib.dir}" includes="serializer*.jar"/>
    </path>

    <!-- <target name="report" depends="xslt-report,copy-images"> -->
    <target name="report" depends="xslt-report">
        <echo>Report generated</echo>
    </target>
    <target name="xslt-report" depends="_message_xalan">
    
      <xslt
            classpathref="xslt.classpath"
            force="true"
            in="${jtlpath}/Timesheet_server_resource.jtl"
            out="${jtlpath}/JMeterResults.html"
            style="${jmeter-home}/extras/jmeter-results-detail-report_21.xsl"/>
    </target>
  
   
    <!-- Copy report images if needed -->
    <target name="copy-images" depends="verify-images" unless="samepath">
        <copy file="${basedir}/expand.png" tofile="${testpath}/expand.png"/>
        <copy file="${basedir}/collapse.png" tofile="${testpath}/collapse.png"/>
    </target>

    <target name="verify-images">
        <condition property="samepath">
                <equals arg1="${testpath}" arg2="${basedir}" />
        </condition>
    </target>

    <!-- Check that the xalan libraries are present -->
    <condition property="xalan.present">
          <and>
              <!-- No need to check all jars; just check a few -->
            <available classpathref="xslt.classpath" classname="org.apache.xalan.processor.TransformerFactoryImpl"/>
            <available classpathref="xslt.classpath" classname="org.apache.xml.serializer.ExtendedContentHandler"/>
          </and>
    </condition>

    <target name="_message_xalan" unless="xalan.present">
          <echo>Cannot find all xalan and/or serialiser jars</echo>
        <echo>The XSLT formatting may not work correctly.</echo>
        <echo>Check you have xalan and serializer jars in ${lib.dir}</echo>
    </target>




</project>  



4.  Run it by command line



ant –Dtest=script run report
 





5.       Result 

HoaLe

4 comments:

  1. Hi, I am following your procedure I am getting the error

    BUILD FAILED
    D:\Gov\Ant\build.xml:93: taskdef class rg.programmerplanet.ant.taskdefs.jmeter.
    JMeterTask cannot be found
    using the classloader AntClassLoader[]

    Total time: 0 seconds

    Please clarify the following questions.

    "testpath" is the path of the .jmx file right?
    What would be the "jmeter.home" and "jmeter-home" paths.

    Please clarify thanks.

    ReplyDelete
  2. add jmeter p;ugin in ant lib folder -- Isha Goomber

    ReplyDelete
  3. Hi,
    In build.xml, I want to add 'jmeter.reportgenerator.exported_transactions_pattern' property. I tried putting it in jmeter > property. But it is not getting recognised. Can you tell me how to make it work?

    ReplyDelete