2013-01-13

How to record steps for load test in JMeter?

In this article we are going to see the process of recording steps in JMeter for Load Testing.

Planning for the test : In the beginning, we have to decide what to test. What should be in the test. After that , we write the steps in doc. For EX- I am writing my steps to test goole search load test. So my steps will be
a. Open Browser and write URL www.google.com
b. Accept certificate if they are asking for that.(In case of https)
c. Write a text in the search text box(I wrote "Example of jmeter recoding)
d. Click Search

After writing the steps, We have to make plan to record in jmeter. Jmeter record steps by capturing data through proxy. So, we have to set a proxy from browser and use a proxy server from jmeter to record that. 

So, Lets start Jmeter Part

1. Download and Install JMeter
2. Run JMeter, It will be opened with a Test plan
3. Add a HTTP Cookie Manager under Test plan[For global cookie]
4. Add a Thread group under Test plan(I have used 3 user for 2 second and 3 cycle to run)
5. Add a Test Fragment under Test plan(Test fragment is the helper for test case making, we will record with this)
 
6. Add Recording Controller under Thread group
 
7. Add a HTTP Proxy Server under Test Fragment

Note : For Jmeter 2.28we will not get by add element under test fragment. We have to add a HTTP proxy server under workbench and then move(cut/past) that under test fragment.
8. Add a Listener(View Results Tree) under HTTP Proxy Server[Optional]

9. Now, See HTTP Proxy Server, I use port 8080 and http client 3.1 for proxy
10. Now, open a browser( I use Firefox) and set proxy as localhost with port 8080.
Note: Use all protocols to use the same proxy
For Firefox :
Tools-> Options -> Advance ->Network ->Connection -> Settings
a. Select, Manual Proxy Configuration
b. Set HTTP Proxy as localhost , port 8080
c. Select Use the proxy server for all protocols
Press ok and come fo main window.
11. From JMeter, HTTP Proxy server, Start the server
11. From browser , Execute the steps that we have planned to do.
- Hit URL www.google.com
- Enter text for search
- Click search button
12. Stop HTTP Proxy server in jmeter
13. Now, Expand Recording Controller and we can see the recorded steps.

Note:
-If we see View Results Tree under HTTP proxy server, we will also see the steps executed and their results
 
-For HTTPS web application, the security certificate should be trusted, and added to the browser..
 
14. Now, Add necessary listener under Thread Group(I have added View Results Tree/View Results in Table)
 
15. Run the test from Run Menu

We have successfully completed recording steps and running that for load testing.
Some time while recording , there may be unnecessary requests gone inside proxy. We need to see and refactor(if needed) the recorded steps.

Tips :
1. You may directly config proxy server to record under Recording Controller .
2. For ajax & JS based page, Add HTTP Cache Manager,HTTP Cookie Manager under the Recording Controller.[It works perforect for ajax requests)

Thanks...:)

2 comments:

  1. Once again, very nice article! It's easy and fun to read for a beginner in JMeter like me. Thanks!

    Few questions:
    1. Why do we need a Cookie Manager and why it's under Test Plan?
    2. Test Fragment goes under Test Plan but Recording Controller goes under Thread Group, why?

    Observations:
    I'm using JMeter 2.11 and I could not find HTTP Proxy Server under Workbench > Add > Non-test elements. Is it now called HTTP(S) Test Script Recorder? Why do we need to create it under workbench and then cut-paste it into Test Fragment?

    Could you please provide any links that explains these? Thanks again!
    --Ishti


    3.

    ReplyDelete
  2. Thanks
    1. Why do we need a Cookie Manager and why it's under Test Plan?
    -> When your web application keeps/maintain cookies
    2. Test Fragment goes under Test Plan but Recording Controller goes under Thread Group, why?
    -> Test fragment refers to a part or group of test steps, so it will be at least with test plan, so that u can use it under different thread groups(if u use multiple groups). Or you can run those fragment independently with different logic controllers.
    Recording controller is initially made for recording steps using proxy. For newer jmeter, we can record steps under all most every container type element (group/set of test steps). So, initially it was kept under recording controller and recording controller will be under group as it runs with it(can not run independently).

    You need to know the idea of work bench, kind of temp items. JMX file stores nothing which are in work bench. Work bench keeps items which are need while making scripts(non storing, like temp). so, the added recorder will not be stored with the test plan you recorded. So, it is kept separately. There are lots of items present in work bench for using .recording just one of them.

    ReplyDelete