How to Run JMeter Script Using Ant

How to Run JMeter Script Using Ant,Apache Ant is a pure Java build tool which is useful in compile,clean and test and run Java applications.Apache JMeter providing option to run JMeter Test Plan using Ant and displays BUILD is successful or Failure and Ant BUILD generates HTML reports after completion of execution of ant.

How to run jmeter script using ant


Also Read


How to Run JMeter Script Using Ant

In this post you will learn How to Run JMeter Script Using Ant,Apache JMeter providing Ant xml file in this path F:\apache-jmeter-3.1\extras, and build.xml file have below details.

<project name="ant-jmeter" default="all">
<description>
Jmeter Ant build description Default Value is "Load Test Results"
</description>
<property name="testpath" value="${user.dir}"/>
<property name="jmeter.home" value="${basedir}/.."/>
<property name="report.title" value="Load Test Results"/>

Function Mode:

<echo>funcMode = ${funcMode}</echo>
<delete file="${testpath}/${test}.html"/>
<jmeter
jmeterhome="${jmeter.home}"
testplan ="${testpath}/${test}.jmx"
resultlog="${testpath}/${test}.jtl">

XSLT Report:

<target name="xslt-report" depends="_message_xalan">
<tstamp><format property="report.datestamp" pattern="yyyy/MM/dd HH:mm"/></tstamp>
<xslt
classpathref="xslt.classpath"
force="true"
in="${testpath}/${test}.jtl"
out="${testpath}/${test}.html"
style="${basedir}/jmeter-results-detail-report${style_version}.xsl">
<param name="showData" expression="${show-data}"/>
<param name="titleReport" expression="${report.title}"/>
<param name="dateReport" expression="${report.datestamp}"/>
</xslt>
</target>

Condition:

<!-- 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>


As you see in above build.xml file i have given three parameters xml values because you need to change those three values as below,please follow below steps to configure.

Build.xml file Configuration:


1.Open build.xml file with notepad or notepad++ and search with " ${test} " and rename with your jmx file name as below.

${test}.jmx - softwaretesting.jmx
${test}.html - softwaretesting.html
${test}.jtl - softwaretesting.jtl

In Function Mode , XSLT report parameter values as below.

Function Mode:

<target name="run">
<echo>funcMode = ${funcMode}</echo>
<delete file="${testpath}/SoftwareTestingdemo.html"/>
<jmeter
jmeterhome="${jmeter.home}"
testplan ="${testpath}/SoftwareTestingdemo.jmx"
resultlog="${testpath}/SoftwareTestingdemo.jtl">

XSLT Report:

<target name="xslt-report" depends="_message_xalan">
<tstamp><format property="report.datestamp" pattern="yyyy/MM/dd HH:mm"/></tstamp>
<xslt
classpathref="xslt.classpath"
force="true"
in="${testpath}/SoftwareTestingdemo.jtl"
out="${testpath}/SoftwareTestingdemo.html"
style="${basedir}/jmeter-results-detail-report${style_version}.xsl">
<param name="showData" expression="${show-data}"/>
<param name="titleReport" expression="${report.title}"/>
<param name="dateReport" expression="${report.datestamp}"/>
</xslt>
</target>

2.Save the build.xml file.
3.Now Copy softwaretesting.jmx file in F:\apache-jmeter-3.1\extras folder as below.
4.Now open Command Prompt.
5.Go to F:\apache-jmeter-3.1\extras folder path
6.Enter ant and press enter,once BUILD is successful then it will display below details in command prompt.
How to run jmeter script using ant

7.Now go to F:\apache-jmeter-3.1\extras folder ,it will generate softwaretesting.jtl,softwaretesting.html files.
Run jmeter script using ant

8.Now open Softwaretesting.html file ,below reports will display all samples related HTML reports.

Load Test Results:



Thank you for reading My post please provide your valuable comments,in case you are facing any problem while generating the reports.

2 comments:

  1. Hi, I tried to run Ant without modifying the build.xml just to the see the results for Test.jmx that JMeter provided, however I kept getting the following error. I don't understand why it keeps saying Test.jtl does not exist as it is supposed to generate it in the end. Any idea?

    run:
    [echo] funcMode = false
    [jmeter] Executing test plan: C:\Users\xxxx\Documents\apache-jmeter-3.1\apache-jmeter-3.1\extras\Test.jmx ==> C:\Users\xxxx\Documents\apache-jmeter-3.1\apache-jmeter-3.1\extras\Test.jtl

    _message_xalan:

    xslt-report:

    BUILD FAILED
    C:\Users\xxxx\Documents\apache-jmeter-3.1\apache-jmeter-3.1\extras\build.xml:124: input file C:\Users\xxxx\Documents\apache-jmeter-3.1\apache-jmeter-3.1\extras\Test.jtl does not exist

    ReplyDelete
  2. After i set up my build.xml as per the above explanation, when i execute tests using ANT, I get error message of missing .jtl file in my extras folder. When I use .jtl from an old run, it reads the results from that old .jtl file and produces html report. It does not execute the tests. Can you please help ?

    ReplyDelete