Why does JMeter behave differently from my browser?
I've set up JMeter to sample the same URLs as my browser, why is JMeter not seeing the same responses?
There are various different reasons for this:
- Cookies - make sure you added a Cookie Manager. Browsers process cookies unless you set them up otherwise, but JMeter does not process cookies unless you add a Cookie Manager.
- User-Agent - the User-Agent is a header that is sent by browsers; it identifies the browser type. Some servers are sensitive to this setting and generate different results for what they think are different browsers. The Header Manager is used to add headers such as User-Agent.
- Hidden fields - if you did not use the JMeter Proxy (or other application) to record the test plan, then it is easy to miss hidden fields from forms.
- Dynamic field names/content - some servers use varying names for fields. So although the test plan may be correct at the time of creation, it does not work when replayed.
- URL rewriting - TBA
How do I solve this?
There are various methods for investigating this.
View Results Tree Listener
This can be used to show the cookies that are received and sent.
Browser add-ons
Some browsers have add-ons that allow one to log the HTTP requests and responses. The JMeter Tree View Listener shows the same data; comparison of the two should show where the JMeter test needs to be modified.
Protocol Analysers
These can analyse the HTTP traffic to and from the JMeter/browser host.
Compare the results to find out where the JMeter test needs to be modified.
Dynamic fields and content
As mentioned above, some servers may use variable names in forms. In this case, the JMeter plan needs to be adjusted to allow for it.
The way to do this is to add a Regular Expression Post Processor to the previous sampler - i.e. the one that returns the form - and extract the appropriate part(s) of the form into JMeter variables.
Then use the variables on the sampler that uses the form.
Example TBA