How to use "loop controller" in jmeter with example

As you know, Apache jmeter has many logic controllers and loop controller is one of the mostly used controller in performance testing of software web application using jmeter. Apache jmeter's thread group is it self loop controller and you can read about 'Loop Count' property of thread group in my previous post. So now your question is 'If
thread group has ability to generate a loop then why require loop controller?'. Answer is - group's 'Loop Count' property forces all sub requests execution multiple time while loop controller will force only specified requests's execution multiple time. Another feature of loop controller is - Apache jmeter will force multiple execution of all sub requests of loop controller before going to next requests of thread group. Let we take one simple example of software web application sample load test.

Created sample software load test of apache jmeter using loop controller as bellow. If you don't know how to create test plan in jmeter then you have to read my post about apache jmeter sample test plan recording steps. Set Number of Threads (users) = 1 and Loop Count = 1 in thread group property. Added Loop Controller in between and moved 'My Account Page' HTTP request under loop controller as shown bellow.


As you see, i set Loop Count = 3. It means all sub requests under loop controller will be executed 3 time. In above case, 'My Account Page' request will be executed 3 time. When i run this test, view result in tree listener shows me requests execution sequence as bellow.

Look here, 'Login' and 'My Orders Page' requests are executed only 1 time while My Account Page's requests is executed 3 time because it is under loop controller and i set Loop Count = 3. Note one thing more is My Orders Page request is executed after completion 3 time execution of My Account Page.

This way if you want to force only few sub request's execution multiple time in your software application performance testing plan then you can use loop controller in your software load test plan.

9 comments:

  1. its really good site to learn the JMeter.

    ReplyDelete
  2. That's easy.
    But.. what if I want to use a variable instead of a number '3'?

    ReplyDelete
    Replies
    1. If its a jmeter variable, you can just use it as ${variable_name} instead of the hardcoded number.

      Delete
  3. How to solve this

    we have login page, account page, home page, news page, contact page.

    use controller to visit them in the following order by two ways.



    login page

    account page

    home page

    news page

    contact page

    account page

    home page

    news page

    contact page

    account page

    home page

    news page

    contact page

    account page

    home page

    news page

    contact page

    ReplyDelete
    Replies
    1. You can use Once Only controller for he login page. Meaning login page will be executed once and then the subsequent pages will be executed based on the loop count under thread group. hope this helps

      Delete
  4. this is the best post for controllers

    ReplyDelete