How to run an JMeter test plan that it should be completed in specified time or it should be terminated within that stipulated time? Please throw me light on this question.
6 Answers
It isn't possible at Test Plan level, but there are following options available:
Set
Duration (seconds)
to the desired value for each Thread GroupUse Test Action timer to stop all the threads (for example, create a separate thread group, add Constant Timer, which will sleep desired number of seconds, when the timer triggers all threads will be requested to stop.
Use Beanshell Sampler anywhere in your script. Relevant Beanshell code to stop the test looks as follows:
SampleResult.setStopTest(true); // to ASK threads to stop SampleResult.setStopTestNow(true); // to TELL threads to stop
Using Duration
or Stop
doesn't mean that your test plan will end at that moment as threads need some time to gracefully shut down.
In case of forceful termination threads may produce extra errors which will be reflected in test results.
Hope this helps.
You can do this by using JMeter Scheduler: In Thread Group tick the Scheduler and set the value as below:
Start Time and End Time: No need to input. keep them as they are, because they have no significant after entering Duration and Startup delay value. Delay overrides Start Time, and Duration overrides End Time.
For example, if you want to run the test for 2 min. Input the value as below:
Duration (seconds): 120
Startup delay (seconds): 0
Now it's the time to run the test: Run -> Start
-
It didn't work for me unless the start time was in the past, despite the startup delay. The endtime didn't have any effect once the duration was there. I'm using version 3.2 though. Oct 14, 2017 at 17:49
Latest Answer,
Just follow the above mentioned steps,
- Select the Thread Group.
- Check the option for the infinite loop.
- Check the option for the Specify Thread lifetime.
- Enter the duration in seconds for the thread group to run.
Let me know if you face any problem in this. :)
-
This answer is the best nowadays. Other answers show obsolete options and menus Jun 14, 2022 at 14:22
-
1@Calabacin Thank you for this comment, it keeps me motivated to do more for the community :) Jul 15, 2022 at 12:24
At my current project we had configuration build with ant and possibility to set properties for Jmeter. With some of them, we used for controlling duration of script execution:
And here is thread group parameters:
config.test.timeout.min
- duration of run in minutes
throughput.freight.offer.permin
- load number of users per minute.
Just one more way of configuring the time for Jmeter script.
To run a JMeter test plan for a specified amount of time, you can follow these steps:
Launch JMeter: Start JMeter by executing the JMeter script or running the jmeter.bat (Windows) or jmeter.sh (Unix/Linux) file.
Create a Test Plan: In the JMeter GUI, create a new Test Plan by right-clicking on the "Test Plan" node in the Test Plan tree and selecting "Add > Threads (Users) > Thread Group".
Configure Thread Group: Set the desired number of threads (virtual users) and other relevant parameters in the Thread Group. Adjust the ramp-up time, iterations, and other settings as needed.
Add Logic Controllers and Samplers: Within the Thread Group, add the necessary Logic Controllers (e.g., Loop Controller) and Samplers (e.g., HTTP Request) to simulate user actions and interactions with the application under test.
Configure Duration: To run the test for a specific duration, add a Timer element to the Thread Group. Right-click on the Thread Group, select "Add > Timer > Constant Timer", and set the desired duration in milliseconds.
Add Listeners: To view and analyze the test results, add listeners such as View Results Tree or Aggregate Report. Right-click on the Thread Group, select "Add > Listener" and choose the desired listener.
Save and Run: Save the Test Plan and run the test by clicking on the "Start" button (green arrow) in the JMeter toolbar. JMeter will execute the test plan for the specified duration.
Monitor and Analyze: During the test execution, you can monitor the progress and performance metrics in the listener(s) added in step 6. After the test completes, analyze the test results to identify any performance issues or bottlenecks.
By configuring the Timer element with the desired duration, you can control the test duration and simulate load for the specified time period using JMeter.