2012-12-19

How to manage User Agents in JMeter

In this following article we are going to see how we can manage different type of user agents to simulate variety browser's hit on a server for load/stress testing. I am using jmeter 2.8.

What is user agent? In short, User Agent is an identity of a client (user). A user agent has details about the client such as OS and its version, browser name and its version. Server processes the requests and provides responses for your browser by identifying using User Agent. User Agent string resides in the header section of each reques
For more detail, please follow wiki. I will try to provide a separate post on user agent.

So, Lets start. 
-First start Jmeter and add a Thread group(10 users, 5 seconds) [For basic idea on jmeter ,see my previous post1 and post2]

-Add a HTTP Request Defaults under Thread group.(I have config the site as www.kaz.com.bd)

-Add a HTTP Header Manager under Thread group

A HTTP Header Manager consists the headers which will be sent along with the request to the server. It usually contains information such as Accept Language, Accept, User Agent, and Accept Encoding.

-Click Add on the bottom of HTTP Header Manager.[A row will be added]

-Click to edit column Name: as User-agent and  column value as
Mozilla/5.0 (iPad; CPU OS 6_0 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Version/6.0 Mobile/10A5355d Safari/8536.25 
I am using this string as Safari 6.0 user agent.
 
If you use Firefox 16.0.1 The string will be

Mozilla/6.0 (Windows NT 6.2; WOW64; rv:16.0.1) Gecko/20121011 Firefox/16.0.1
Or Internet Explorer 10.6 The string will be
Mozilla/5.0 (compatible; MSIE 10.6; Windows NT 6.1; Trident/5.0; InfoPath.2; SLCC1; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; .NET CLR 2.0.50727) 3gpp-gba UNTRUSTED/1.0

A full list of different user agents text string is present in this link and this link

-Add a Loop controller [this is a Logic controller] under Thread group(select forever )

-Add a Http request [This is a Sampler]under loop controller and provide path.(i use /index.html for home path on KAZ's site)

-Add View Results Tree under Thread group
-Now, Run the thread and see RAW and HTTP Request from View Results Tree.






We can see the user agent string that is passed through http header.

Note :
-Only one user agent can be used in HTTP Header Manager which is under thread group.
-If any other HTTP Header Managers are under other http request, remove/delete/disable them. Without this, main HTTP Header Manager will not work.
-In this example , the main focus is on user agent changing based on http header manager. Other detail descriptions are kept small.

.... Thanks....:) 

4 comments:

  1. User agent set to firefox but still using IE...Any option I am missing ?

    ReplyDelete
    Replies
    1. !!!... please check the string. Check that the header manager is at the before(& top) the requests.(make sure, not s child or later steps). You may send me jmx file.

      Delete
  2. Hi, in my network my application is working successfully in IE but on chrome I can access my application(manually). and in Jmeter also my application is not accessible; I was wondering if I can set IE to be used? I am not sure how exactly User Agent works for Jmeter. Can you help me

    ReplyDelete
    Replies
    1. jmeter cant access chrome.what are you trying to do?

      if you want jmeter using user-agent of IE in header manager, you can always do that.

      but , if you want jmeter to drive chrome to test, then it will not be a load test. it will be browser timing test.

      mail me details on what you want.

      Delete