Recording a test in JMeter
Basic Recording in JMeter:
1) open JMeter and add a "Http Proxy Server" (under "Non-Test Elements") to "Workbench". A good idea is to select "Add Assertions" I'll go into this later.
2) Under Test Plan, add a Thread Group.
3) Configure the Http Proxy Server to use the Thread Group as the Target Controller. Also make sure to note the port for the proxy server (default 8080, change if it conflicts with something).
4) Open Firefox, Tools->Options->Connection Settings: select Manual Proxy and specify "localhost" and the port from Step 3.
5) In JMeter, Go to your Http Proxy Server, and click the "Start" button.
6) Go back to Firefox and start using the site you want to test.
You should see requests start to populate under "Thread Group"
You have now recorded some interactions. Take a look at them, do you see requests for things you don't want to reproduce when you run the test plan? Images, style-sheets, requests to external sites that slipped through?
Preventing unnecessary requests during recording:
1) To prevent requests for certain file-types (images, javascript files, css files, use the "Exclude Patterns" box in the Http Proxy Server item, entering a regex pattern. To exclude all requests for .gif file being recorded, specify .*\.gif
*NEW* Use a Cookie Manager.
Before running any test, place a Cookie Manager(Config Element) under the Thread Group (at the same level as the recorded requests). You'll need this if your site uses Cookies (i.e. for user management) Better safe than sorry. Also, check "Clear cookies each iteration".
Displaying results:
You'll probably want to see if you succeeded or not, so add the following to "Thread Group": Listeners->"View Results in Table" and Listeners->"View Results in Tree". The table will give you a run down of successful/unsuccessful tests and the tree will display both request info and response data.
Response assertions:
If you had the Http Proxy automatically add Response Assertions, you should have a "Check Respons" item under each request item. Here you can use some regex patterns to either check for expecting text, or text that should not be there. Evaluations of these Response Assertions will affect whether the request is considered a Fail or Pass (as shown in the Results).
Advanced proxy filtering:
Originally I had a proxy set up in firefox that would forward all requests to localhost:8090, but this was messy.
1) I had to keep enabling/disabling it depending on whether I was running the Http Proxy for a test or not.
2) If, while I was recording a test case, some other web-site loaded by Firefox made a request automatically (i.e. gmail updating itself, or a banner ad javascript getting a new ad), I'd have unnecessary requests sprinkled through my test case, so I wrote the following proxy.pac file:
function FindProxyForURL(url, host) {
if ((host == 'localhost') || (host == '127.0.0.1')) {
return "PROXY 127.0.0.1:8090; DIRECT";
}
else {
return "DIRECT";
}
}
Now in Firefox, Tools->Options->Connection Settings: Select "Autiomatic Proxy Configuration File" and specify "file:///C:/Proxy.pac"
The above Proxy.pac file looks at each request coming through the browser, and if the host is "localhost" or this computer's IP, then it tries in the following order, 1) the proxy at 127.0.0.1:8090 (our JMeter proxy), 2) a direct connection.
If the host of the request is anything else, then it does NOT go through the proxy, it is Direct.
This assumes the site you're recording is deployed on your machine. If you're running JMeter against a different host to record, you'd want to change the line:
if ((host == 'localhost') || (host == '127.0.0.1')) {
to: if (host == 'www.yahoo.com')
AI Summary
2 Comments
Added "Cookie Manager" section.
this is awesome. Thanks!
by