xilducex
xilducex

Reputation: 13

How to use Ant Script to Start and Stop JMeter test

I'm new to JMeter and Ant and my web searches have not been fruitful so I'm posing a question here: Is it possible to start and stop a JMeter script using Ant?

Here's what I'm trying to do: I have a JMeter test plan with a loop in it that is to simulate a user (or several users) sitting on a page for an indeterminate amount of time after a page refresh. In JMeter GUI mode, I can schedule the thread group to spin up users at a specified time and continue doing so for a specified duration. I'd ideally run this script for 45 minutes or so, stop the script and analyze the results. I would like to automate the running of this script and Ant seemed like the way to go. I did not see an appropriate property to specify a start time or a duration when running the script. Does such a thing exist? Is there a suitable workaround? Any help that can be offered is greatly appreciated.

Upvotes: 0

Views: 1176

Answers (2)

Dmitri T
Dmitri T

Reputation: 168122

There is a JMeter Ant Task available. You can kick off your Test Plan using this Task according to documentation.

For 45 minutes test duration I would go for the following:

<jmeter
    jmeterhome="/path/to/your/JMeter/installation"
    testplan="/path/to/your/test/plan.jmx"
    resultlog="/path/to/your/test/results.jtl">
    <property name="duration" value="2700"/>        
</jmeter>

And put ${__P(duration,)} into Thread Group Scheduler's "Duration" input field

Thread Group Duration

Once you start Ant JMeter will pick up that "duration" property and ask threads to stop when 2700 seconds (45 minutes) pass. Remember that in case of high number of threads shut down process may not be immediate as JMeter might need some time to gracefully shut down all the test threads.

For detailed explanation on using JMeter Ant Task and few more options of running tests in non-GUI mode see 5 Ways To Launch a JMeter Test without Using the JMeter GUI guide.

Upvotes: 2

Nachiket Kate
Nachiket Kate

Reputation: 8571

From what have you written I think you want to schedule a test from non-gui mode and control the parameters also. I am not sure about ant but we have workaround.

For this you can use JMeter non-gui features

  1. If you want to start a test then you can use Jmeter.bat/.sh -n -t
  2. You can stop the test using stoptest.bat/.sh and shutdown.bat/.sh at any time (Maybe a wrapper shell/batch script can help you to automate this)
  3. For specifying parameters you can override the existing parameters by specifying them from command line as properties local/global like,

    -D[prop_name]=[value] - defines a java system property value
    -J[prop name]=[value] - defines a local JMeter property  
    

and use these properties in your test plan so that you can pass values while running the test for a specific amount of time or infinitely and stop the test in between (like you said after 45 min) using stoptest.bat/.sh

Example,

In Thread Group set Number of Threads to ${__property(users,,)} and specify it from command line as,

jmeter -Jusers=50 -n -t Test_Plan.jmx

Remember this local property and not global.

For using properties and non-gui mode you can refer this, Jmeter Manual

Upvotes: 0

Related Questions