Jmeter Basics Learning


Apache JMeter is open source software.
100% pure Java desktop application, designed to load test functional behavior and measure performance of web sites.

Version Tested: jmeter 2.3.4 tested from October 2009 until February 2010
License & Pricing: Open Source

Functionalities :
Apache JMeter may be used to test functional and performance both on static and dynamic resources (files, Servlets, Perl scripts, Java Objects, Data Bases and Queries, FTP Servers and more).
It can be used to simulate a heavy load on a server, network or object to test its strength or to analyze overall performance under different load types.
We can also use it perform a functional test on websites, databases, LDAPs, webservices etc.
JMeter is not a browser.
JMeter looks like a browser (or rather, multiple browsers) because of web-services and remote services, however JMeter does not perform all the actions supported by browsers.
In particular, JMeter does not execute the Javascript found in HTML pages.

How to Install JMeter:
The installation of JMeter (if you would call it an installation) is pretty straight forward. On the website is a link to the download area of stable versions.
Download the latest version (zip or tgz) and unpack the archive to a local folder.
Before starting JMeter it is wise to have a look at the configuration.
The jmeter.properties file (located in the bin folder) contains a lot of settings. Most of those settings should be fine for the average user. The file is well documented and easy to read (and change where needed).
Also pay attention to needed additional jars. If you are going to use for example JDBC, JMS or JavaMail additional jars are not included in the JMeter installation. Starting JMeter is just a matter of double clicking jmeter.bat in the bin folder.


Settings Before starting JMeter recording :

Open JMeter

1.       Open JMeter by double clicking jmeter.bat in the bin folder.
2.       JMeter screen will be look like this (Refer the screen shot)





















What is test plan?
A Test Plan can be viewed as a container for running tests. It defines what to test and how to go about it. A complete test plan consists of one or more elements such as thread groups, logic controllers, sample-generating controllers, listeners, timers, assertions, and configuration elements. A test plan must have at least one thread group.

Creating Thread Group under Test plan :
Thread Group elements are the beginning points of your test plan. As the name suggests, the thread group elements control the number of threads JMeter will use during the test. We can also control the following via the Thread Group:

Setting the number of threads

Setting the ramp-up time

Setting the number of test iterations

The Thread Group Control Panel looks like this:


Select Test plan (Right Click) -> Select Add -> Select Threads (Users) -> Select Thread Group




















The Thread Group Panel holds the following components:

·         Action to be taken after a Sampler error: 
In case any error occurs during test execution, you may let the test either:

Continue to the next element in the test

Stop Thread to stop the current Thread.

o    Stop Test completely, in case you want to inspect the error before it continues running.

·         Number of Threads: Simulates the number of users or connections to your server application.

·         Ramp-Up Period: Defines how long it will take JMeter to get all threads running.

·         Loop Count: Defines the number of times to execute the test.

·         Scheduler checkbox: Once selected, the Scheduler Configuration section appears at the bottom of the control panel.

·         Scheduler Configuration: You can configure the start and end time of running the test.

 A Thread Group defines a pool of users that will execute a particular test case against your server. 

Number of threads :- In the Thread Group GUI, you can control the number of users simulated
The ramp up time :- how long it takes to start all the threads
Loop Count :- The number of times to perform the test, and optionally
Scheduler :-

-          A start and stop time for the test.
-          Duration of the test in Seconds
-          Startup delay means the script is going to run after the specified delay.
When using the scheduler, JMeter runs the thread group until either the number of loops is reached or the duration/end-time is reached - whichever occurs first. Note that the condition is only checked between samples; when the end condition is reached, that thread will stop.
JMeter does not interrupt samplers which are waiting for a response, so the end time may be delayed arbitrarily. 




















Refer the screen shot: How to add Thread group.

Add HTTP Request Default:  If you need to test dozens of http urls, then instead of adding the webserver's hostname or proxy details etc in all HTTP Request Samplers, you can put these in The Config Element HTTP Request Defaults. This will avoid repetition of data and also make the config manageable. Let's see an HTTP Config Element in action






















Add HTTP Cookie Manager : This cookie manager stores and send the cookies just as a browser do. If your HTTP Request response contains a cookie, the Cookie Manager automatically stores that cookie and will use it for all future requests to that particular web site. Use of cookies eventually becomes necessary when you application has to maintain session, like once your login to an application, it maintains the session of that user so that he/she can work inside the application. If that session is not maintained (via Cookie Manager in case of JMeter), then user will logged out of the application as soon as he/she sends next request which requires Authentication.



















Inside cookie manager:









Add User Define Variable: If we  have a number of HTTP Requests that have different parameters set but the same URLs. But you know that in future you may want to edit URL. So, what you have to do in such case is to edit EVERY URL. But if you have hundreds of them, it is not good idea.In this case User Defined Variables (UDV) will be better solution. This functionality allows changing parameters in multiple places of test-plan.We can as many as user define variable in Jmeter which are further used in our scripts for example current Date variable























Inside UserDefineVariable









Add HTTP Header Manager : Each time the browser sends a request to a server, headers with additional information are attached to the request. When documenting to the HTTP protocol, a large number of them are described. Still, a group with many used headers can be allocated: Accept-Language, Accept-Encoding, User-Agent, Referer.



















Accept-Encoding :

 The accept-encoding header tells the server which coding method the server should select before sending the response to a client. In our case “gzip” and “deflate” are algorithms of compressing data before sending it to end user. There are more options related to Accept-Encoding (do a quick 'Google' for the description).  In this scenario, take note that using data compression decreases the load on the network and increases the load on the CPU.









Add Recording Controller:
11.     Select Thread Group (Right Click) -> Select Add -> Select Logic Controller -> Select Recording  Controller.
22.     The Recording Controller is a place holder indicating where the proxy server should record samples   to.
33.   During test run, it has no effect, similar to the Simple Controller. But during recording using the HTTP(S) Test Script Recorder , all recorded samples will by default be saved under the Recording Controller.
44.   Name: - Descriptive name for this controller that is shown in the tree.



    

   Refer the screen shot: How to add recording controller.


    Refer the screen shot : How will be the screen after adding recording controller.
    Add HTTP(S) Test Script Recorder:

     1. Select Work Bench (Right Click) -> Select Non-Test Elements -> Select HTTP(S) Test Script Recorder.


   










 

   Refer the screen shot : How to add the HTTP script recording controller.
     1.       The HTTP(S) Test Script Recorder allows JMeter to intercept and record your actions while you         browse your web application with your normal browser.
     2.       JMeter will create test sample objects and store them directly into your test plan as you go (so you      can view samples interactively while you make them).
     3.       The recorder is implemented as an HTTP(S) proxy server. You need to set up your browser use           the  proxy for all HTTP and HTTPS requests. [Do not use JMeter as the proxy for any other                 request types - FTP, etc. - as JMeter cannot handle them.]
    4.       Ideally use private browsing mode when recording the session.
            
     5.   This should ensure that the browser starts with no stored cookies, and prevents certain changes from                being saved. For example, Firefox does not allow certificate overrides to be saved permanently.

         Includes and Excludes :

               1.       The include and exclude patterns are treated as regular expressions.

2.       They will be matched against the host name, port (actual or implied) path and query (if any) of each browser request.
3.       If the URL you are browsing is
"http://jmeter.apache.org/jmeter/index.html?username=xxxx" ,
then the regular expression will be tested against the string:
"jmeter.apache.org:80/jmeter/index.html?username=xxxx" .
4.       Thus, if you want to include all .html files, your regular expression might look like:
".*\.html(\?.*)?" - or ".*\.html" if you know that there is no query string or you only want html pages without query strings.
5.       If there are any include patterns, then the URL must match at least one of the patterns , otherwise it will not be recorded.
6.       If there are any exclude patterns, then the URL must not match any of the patterns , otherwise it will not be recorded. Using a combination of includes and excludes, you should be able to record what you are interested in and skip what you are not.
7.       HTTP test script recorder page
1)       Uncheck the check box “capture HTTP headers”
2)      Copied the URL pattern to exclude (from help)
(.*\.html(\?.*))
(.*\.css(\?.*))
(.*\.png(\?.*))
(.*\.js(\?.*))
(.*\.gif(\?.*))
(.*\.jsp(\?.*))
                                        (.*\.jpg(\?.*))






  

















    Browser settings
    1.       Go to Mozilla – Tools –Options –Advanced –Network –Settings
         Manual proxy configuration need to select

        HTTP proxy – localhost :8080


   



















   Record Normal flows after all above settings

    After above settings you can do your manual flow Jmeter will automatically record your scripts


   Settings after Recording the Scenarios :

            


















 

 1.       Random controller: - Select Thread Group (Right Click) -> Select add ->Select Logic                                                             controller -> Select Random Controller.
                 -          The Random Logic Controller acts similarly to the Interleave Controller
   2.       Once only controller: - Select Thread Group (Right Click) -> Select add ->Select Logic                                               controller -> Once only Controller.
-           The Once Only Logic Controller tells JMeter to process the controller(s) inside it only once per Thread, and pass over any requests under it during further iterations through the test plan.
-          The Once Only Controller will now execute always during the first iteration of any looping parent controller.
-          Thus, if the Once Only Controller is placed under a Loop Controller specified to loop 5 times, then the Once Only Controller will execute only on the first iteration through the Loop Controller (ie, every 5 times).
-          For testing that requires a login, consider placing the login request in this controller since each thread only needs to login once to establish a session.


3.       Loop Controller: - Select Thread Group (Right Click) -> Select add ->Select Logic controller -> Loop Controller.
-          If you add Generative or Logic Controllers to a Loop Controller, JMeter will loop through them a certain number of times, in addition to the loop value you specified for the Thread Group.
-          For example, if you add one HTTP Request to a Loop Controller with a loop count of two, and configure the Thread Group loop count to three, JMeter will send a total of 2 * 3 = 6 HTTP Requests.
4.       Aggregate graphs Select Thread Group (Right Click) -> Select add ->Select Listener -> Select Aggregate graphs.
-          Aggregate graph is nothing but aggregate report

5.       View results tree Select Thread Group (Right Click) -> Select add -> Select Listener -> Select view result tree
-          Used to Check the sample response at the time of JMeter Execution

6.       View results in table Select Thread Group (Right Click) -> Select add -> Select Listener -> Select results in table
-          This visualizer creates a row for every sample result. Like the View Results Tree , this visualizer uses a lot of memory.
                      By default, it only displays the main (parent) samples; it does not display the sub-samples (child                                 samples). Versions of JMeter after 2.5.1 have a "Child Samples?" check-box. If this is selected,                               then the sub-samples are displayed instead of the main samples


                Importing Excel sheet in to JMeter: - Loop Controller(Right click) -> Add -> Config element ->CSV data set                                                                             Config


     
















   1. In above image the file name is nothing but your csv file(Note: If your csv file located in different folder then you have to mention file path in file name field

       Ex: FolderName/FileName.csv

    2. Variable Name :  It is the name which is used for parameterization .Each name refer particular column values in CSV and column are separated by “,”
      Ex: columnName1, columnName2, columnName3

     Additional Info:
1.       CSV Data Set Config is used to read lines from a file, and split them into variables.
2.       It is easier to use than the __CSVRead() and _StringFromFile() functions.
3.       It is well suited to handling large numbers of variables, and is also useful for testing with "random" and unique values.
4.       Generating unique random values at run-time is expensive in terms of CPU and memory, so just create the data in advance of the test. If you want each thread to have its own set of values, then you will need to create a set of files, one for each thread. For example test1.csv, test2.csv,... testn.csv. Use the filename test${__threadNum}.csv and set the "Sharing mode" to "Current thread".
5.       As a special case, the string "\t" (without quotes) in the delimiter field is treated as a Tab.
6.       When the end of file (EOF) is reached, and the recycle option is true, reading starts again with the first line of the file.
7.       If the recycle option is false, and stopThread is false, then all the variables are set to <EOF> when the end of file is reached.
8.       This value can be changed by setting the JMeter property csvdataset.eofstring


Thanks  Guys For Reading My Post

Please feel free to comment your queries .

Comments

Post a Comment

Popular posts from this blog

How To Run JMeter GUI Mode In Ubuntu Servers

SELENIUM

Sql Basics With Examples