Ever wanted to simulate sudden load on your web application to see how it performs ? Jmeter is a wonderful tool to run and test these simulations against any web application, before you subject it to real time user behavior.
Jmeter comes out-of-the-box with several varieties of Timer elements for testing various performance test scenarios. But these timers are always acts before executing the sampler where it was defined in the test script. Like shown in the pic below.
In the test plan above, Jmeter delays the 'First Request' by the time specified by the 'Constant Timer' before launching the 'Second Request'.
What if you want to send more than one HTTP samples and wait for sometime before proceeding to the next HTTP Sample in the test case ?
An easier approach is to introduce the timer as a third element in your test.
Yes, its not going to work as expected as the 'Constant Timer' now acts before lauching each request within the thread group. So, if you gave the Timer value as 1 sec then the sequence of events follow the order shown below..
1.Wait 1 sec
2.Launch 'First Request'
3.Wait 1 sec
4.Launch 'Second Request'
Clearly not what we expected.. How do we fix this problem ?
Test Action Sampler comes to rescue here. We can quickly replace the Timer element with a Test Action Sampler with a delay of 1 Sec. The new Test Plan looks like this..
Now the resulting Test Case will run in the following order.
1.Launch First Request
2.Launch Second Request
3.Wait for 1 Sec
Which is precisely what we want in our test scenario.
Test Action can come in handy if you want to introduce variable delays in your Test Cases. You can also combine this sampler within the 'If Controller' component of Jmeter to introduce smart delays in your applications.
You can also introduce random delays into your test case by adding a Random Timer as a child to the 'Test Action' Sampler. Please note that you should select the 'Pause' option in the configuration and set the pause to 0, in order for this to work.
Jmeter is a wonderful tool to automate functional and performance test your web applications. It comes with plenty of Samplers out-of-the-box which you can use to define any test scenario with any amount of complexity. To make it more awesome, its even very simple to extend the Samplers by writing your own...
Happy Performance Testing....