You are on page 1of 32

Jmeter Understanding Document

Document Revision History

Created/ Modified By

Reviewed By

Date

Vikas Singh

Table of Contents
Introduction ...................................................................................................................................................................3 Getting Started ..........................................................................................................................................................3 Requirements ............................................................................................................................................................3 Apache JMeter Step-by-step .........................................................................................................................................3 Basic Proxy Instructions ............................................................................................................................................3 Configure your browser to use the JMeter HTTP Proxy ............................................................................................7 Record your navigation .............................................................................................................................................9 Start the test ...........................................................................................................................................................10 Building a Web Test Plan .............................................................................................................................................11 Adding Users ...........................................................................................................................................................11 Adding Default HTTP Request Properties................................................................................................................12 Adding Cookie Support............................................................................................................................................12 Adding HTTP Requests ............................................................................................................................................12 Adding a Listener to View Store the Test Results ....................................................................................................14 Building an API Test Plan .............................................................................................................................................14 Adding Users ...........................................................................................................................................................15 Adding the Http Sampler .........................................................................................................................................15 Adding the CSV Data Set Config ..............................................................................................................................17 Add Assertions ........................................................................................................................................................18 Building a WebService Test Plan ..................................................................................................................................21 Adding Users ...........................................................................................................................................................21 Adding WebService Requests ..................................................................................................................................21 Adding a Listener to View Store the Test Results ....................................................................................................22 Building a Database Test Plan ......................................................................................................................................22 Adding Users ...........................................................................................................................................................22 Adding JDBC Requests .............................................................................................................................................23 Adding a Listener to View/Store the Test Results ...................................................................................................26 Correlation in Jmeter ...................................................................................................................................................26 Steps of Correlation: ...............................................................................................................................................27 Jmeter Parameterization .............................................................................................................................................29 Apache Jmeter Advantages .........................................................................................................................................31

Introduction
Apache Jmeter is a 100% pure Java desktop application designed to load test client/server software (such as a web application). It may be used to test performance both on static and dynamic resources such as static files, Java Servlets, CGI scripts, Java objects, databases, FTP servers, and more. Jmeter 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. Additionally, Jmeter can help you regression test your application by letting you create test scripts with assertions to validate that your application is returning the results you expect. For maximum flexibility, Jmeter lets you create these assertions using regular expressions.

Getting Started
The easiest way to begin using JMeter is to first download the latest production release and install it. The release contains all of the files you need to build and run most types of tests, e.g. Web (HTTP/HTTPS), FTP, JDBC, LDAP, Java, and JUnit.

Requirements
JMeter requires a fully compliant JVM 1.5 or higher. JMeter is a 100% Java application and should run correctly on any system that has a compliant Java implementation. Operating systems tested with JMeter can be view on this page on JMeter wiki. Even if your OS is not listed on the wiki page, JMeter should run on it provided that the JVM is compliant.

Apache JMeter Step-by-step


Basic Proxy Instructions
1. Go to JMETER_HOME/bin and start JMeter with jmeter.bat on Windows 2. Select Test Plan on the tree 3. Right click on the Test Plan and add a new thread group: Add > Threads (Users) > Thread Group

4. Select the Thread Group 5. Right click Add -> Config Element -> HTTP Request Defaults

6. In new HTTP Request Defaults element: Server name enter jmeter.apache.org 7. Path leave blank

8. Right click on the Thread Group and add a recording controller: Add > Logic Controller >Recording Controller 4

9. Next, select Workbench 10. Right click on Workbench and add the Http proxy: Add -> Non-Test Elements -> HTTP Proxy Server

11. On HTTP Proxy Server, click the Add button in URL Patterns to Include. This will Create a blank entry. 12. Enter .*\.html 13. Click 3 times, the Add button in URL Patterns to Exclude. This will create 3 blank Entries. 14. Enter .*\.png pattern, .*\.gif pattern and .*\.ico pattern

15. Right click on HTTP Proxy Server and add a listener: Add -> Listener -> View Results Tree

16. Return to HTTP Proxy Server, and click the Start button at the bottom 6

Configure your browser to use the JMeter HTTP Proxy


At this point, JMeter's proxy is running. For this exercise, we will use Iceweasel/Firefox /IE to view some pages on JMeter. 13. Start Iceweasel/Firefox, but do not close JMeter. 14. From the tool bar, click Edit -> Preferences (or Tools > Preferences). This should bring up the options. 15. Select the Advanced tab, and Network tab 16. Click Settings button near the bottom.

17. On the new popup, check Manual proxy configuration. The address and port fields should be enabled now. 18. Address enter localhost or the IP address of your system 19. Port enter 8080. 20. Check Use this proxy server for all protocols

21. Click ok button 8

22. Click ok button again. This should return you to the browser

Record your navigation


23. With your browser, in the Address bar at the top, enter http://jmeter.apache.org/index.html and hit the enter key. 24. Click on a few links on JMeter's pages. 25. Close your browser and bring up the JMeter window. Expand the thread group and there should be several samplers. At this point, the test plan can be saved as is. If you forget to add default http request settings, you will have to manually delete the server name, and port.

In this sample, there aren't any default request parameters. If a particular request parameter is required by all pages, the request defaults are where one would add the entries. 25. Select Thread Group 26. Right click Add -> Listener -> Summary Report to add an summary listener.

27. The summary listener will show some basic statistics. 9

27. Select Thread Group 28. Number of Threads enter 5 29. Ramp up Period do not change 30. Loop Count enter 100

Start the test


At this point, we are ready to run our test plan and see what happens. Save the test plan. When you're ready to run the test, there's two ways: 1. Run -> Start 2. CtrlR Before you start the test, select Summary Report. As the test runs, the statistics will change until the test is done. At the end of the test, the summary report should look like this.

While the test is running, in the upper right-hand corner, there should be a green square. When the test is done, the box should be grey.

10

Building a Web Test Plan


In this section, you will learn how to create a basic Test Plan to test a Web site. You will create five users that send requests to two pages on the JMeter Web site.

Adding Users
The first step you want to do with every JMeter Test Plan is to add a Thread Group element. The Thread Group tells JMeter the number of users you want to simulate, how often the users should send requests, and the how many requests they should send. Go ahead and add the Thread Group element by first selecting the Test Plan, clicking your right mouse button to get the Add menu, and then select Add --> Thread Group.

For example, if you enter a Ramp-Up Period of 5 seconds, JMeter will finish starting all of your users by the end of the 5 seconds. So, if we have 5 users and a 5 second Ramp-Up Period, then the delay between starting users would be 1 second (5 users / 5 seconds = 1 user per second). If you set the value to 0, then JMeter will immediately start all of your users. Finally enter a value of 2 in the Loop Count field. This property tells JMeter how many times to repeat your test. If you enter a loop count value of 1, then JMeter will run your test only once. To have JMeter repeatedly run your Test Plan, select the Forever checkbox.

11

Adding Default HTTP Request Properties


Now that we have defined our users, it is time to define the tasks that they will be performing. In this section, you will specify the default settings for your HTTP requests. And then, in section 5.3, you will add HTTP Request elements which use some of the default settings you specified here. Begin by selecting the JMeter Users (Thread Group) element. Click your right mouse button to get the Add menu, and then select Add --> Config Element --> HTTP Request Defaults. Then, select this new element to view its Control Panel

The HTTP Request Defaults element does not tell JMeter to send an HTTP request. It simply defines the default values that the HTTP Request elements use.

Adding Cookie Support


Nearly all web testing should use cookie support, unless your application specifically doesn't use cookies. To add cookie support, simply add an HTTP Cookie Manager to each Thread Group in your test plan. This will ensure that each thread gets its own cookies, but shared across all HTTP Request objects. To add the HTTP Cookie Manager , simply select the Thread Group , and choose Add --> Config Element -> HTTP Cookie Manager, either from the Edit Menu, or from the right-click pop-up menu.

Adding HTTP Requests


In our Test Plan, we need to make two HTTP requests. The first one is for the JMeter home page (http://jmeter.apache.org/), and the second one is for the Changes page (http://jmeter.apache.org/changes.html). 12

Start by adding the first HTTP Request to the JMeter Users element (Add --> Sampler --> HTTP Request). Then, select the HTTP Request element in the tree and edit the following properties Change the Name field to "Home Page". Set the Path field to "/". Remember that you do not have to set the Server Name field because you already specified this value in the HTTP Request Defaults element.

Next, add the second HTTP Request and edit the following properties Change the Name field to "Changes". Set the Path field to "/changes.html".

13

Adding a Listener to View Store the Test Results


The final element you need to add to your Test Plan is a Listener. This element is responsible for storing all of the results of your HTTP requests in a file and presenting a visual model of the data. Select the JMeter Users element and add a Graph Results listener (Add --> Listener --> Summary Results).

Building an API Test Plan


In this section, you will learn how to create a Test Plan to test a yahoo weather API. To show the how to create the API Test Plan i am using Yahoo Weather API for Demo purpose. http://weather.yahooapis.com/forecastrss?w=2442047&u=c Input 1 : W = 2442047 >>> Location Id Input 2 : u = c >> Celsius( Temp ) If User direct Request the above url then it would return response like : Yahoo! Weather - Los Angeles, CA Yahoo! Weather for Los Angeles, CA 14

Conditions for Los Angeles, CA at 6:47 pm PST Friday, December 14, 2012 8:17 AM Current Conditions: Fair, 12 C Forecast: Thu - Partly Cloudy. High: 16 Low: 8 Fri - Partly Cloudy. High: 14 Low: 9 Full Forecast at Yahoo! Weather (provided by The Weather Channel)

To Automate the above requirement follow the Step below :

Adding Users
Add the Thread Group (Test plan >>Thread Group

Adding the Http Sampler


Add the Http Sampler (Thread Group >>Add>>Sampler HTTP Request) and add the Server name/ IP= weather.yahooapis.com in Path put the forecastrss? w=2442047&u=c

15

1. Now Server name/ IP= weather.yahooapis.com ,w=2442047 and u =c need to be parameterized replace them with ${location} and ${format} Refer the snapshot below :

16

Adding the CSV Data Set Config


Add CSV Data Set Config (Http Request >>Config Element>> CSV Data Set Config) provide the File name of csv file and Variables location, format

17

Refer screenshot for details

2. Add Test data in CSV File

Add Assertions
To verify the API is working or not Add the Assertion Response Assertion: (Http Request >>Assertions>>Response)

18

In this case you can add the Location name in text response Pattern and parameterize the assertion text. Refer Snapshot below

Add XPath Assertion: To Verify the Nodes of XML (Http Request >>Assertions>> XPath Assertion)

XML Schema Assertion>>To Verify the XML w.r.t to Schema (Http Request >>Assertions>> XML Schema Assertion)

Provide the Schema file name and Location.

19

XML Assertion: To Verify XML Format (Http Request >>Assertions>> XML Assertion)

Assertion Results: Results of applied Assertions ((Http Request >>Listener>> Summary Assertion Results)

20

Building a WebService Test Plan


In this section, you will learn how to create a Test Plan to test a WebService.

Adding Users
The first step you want to do with every JMeter Test Plan is to add a Thread Group element. The Thread Group tells JMeter the number of users you want to simulate, how often the users should send requests, and the how many requests they should send.

Adding WebService Requests


Start by adding the sampler WebService (SOAP) Request to the Jakarta Users element (Add --> Sampler -> WebService (SOAP) Request). Then, select the webservice Request element in the tree and edit the following properties 1. Change the Name field to "WebService (SOAP) Request". 2. Enter the WSDL URL and click "Load WSDL".

If the WSDL file was loaded correctly, the "Web Methods" drop down should be populated. If the drop 21

down remains blank, it means there was a problem getting the WSDL. You can test the WSDL using a browser that reads XML. For example, if you're testing an IIS webservice the URL will look like this: http://localhost/myWebService/Service.asmx?WSDL. At this point, SOAPAction, URL and SOAP Data should be blank. Next, select the web method and click "Configure". The sampler should populate the "URL" and "SOAPAction" text fields. Assuming the WSDL is valid, the correct soap action should be entered. The last step is to paste the SOAP message in the "SOAP/XML-RPC Data" text area. You can optionally save the soap message to a file and browse to the location. For convienance, there is a third option of using a message folder. The sampler will randomly select files from a given folder and use the text for the soap message. If you do not want JMeter to read the response from the SOAP Webservice, uncheck "Read Soap Responses." If the test plan is intended to stress test a webservice, the box should be unchecked. If the test plan is a functional test, the box should be checked. When "Read Soap Responses" is unchecked, no result will be displayed in view result tree or view results in table. An important note on the sampler. It will automatically use the proxy host and port passed to JMeter from command line, if those fields in the sampler are left blank. If a sampler has values in the proxy host and port text field, it will use the ones provided by the user. If no host or port are provided and JMeter wasn't started with command line options, the sampler will fail silently. This behavior may not be what users expect.

Adding a Listener to View Store the Test Results


The final element you need to add to your Test Plan is a Listener. This element is responsible for storing all of the results of your HTTP requests in a file and presenting a visual model of the data.

Building a Database Test Plan


In this section, you will learn how to create a basic Test Plan to test a database server. You will create ten users that send five SQL requests to the database server. This example uses the MySQL database driver. To use this driver, its containing .jar file must be copied to the JMeter lib directory

Adding Users
Go ahead and add the ThreadGroup element by first selecting the Test Plan, clicking your right mouse button to get the Add menu, and then select Add --> ThreadGroup.

22

Adding JDBC Requests


Begin by selecting the JDBC Users element. Click your right mouse button to get the Add menu, and then select Add --> Config Element --> JDBC Connection Configuration. Then, select this new element to view its Control Panel Set up the following fields (these assume we will be using a local MySQL database called test):

Variable name bound to pool. This needs to uniquely identify the configuration. It is used by the JDBC Sampler to identify the configuration to be used. Database URL: jdbc:mysql://localhost:3306/test JDBC Driver class: com.mysql.jdbc.Driver Username: guest Password: password for guest

The other fields on the screen can be left as the defaults. JMeter creates a database connection pool with the configuration settings as specified in the Control Panel. The pool is referred to in JDBC Requests in the 'Variable Name' field. Several different JDBC Configuration elements can be used, but they must have unique names. Every JDBC Request must refer to a JDBC Configuration pool. More than one JDBC Request can refer to the same pool.

23

Selecting the JDBC Users element again. Click your right mouse button to get the Add menu, and then select Add --> Sampler --> JDBC Request. Then, select this new element to view its Control Panel

24

In our Test Plan, we will make two JDBC requests. The first one is for Eastman Kodak stock, and the second is Pfizer stock (obviously you should change these to examples appropriate for your particular database). These are illustrated below. Start by editing the following properties

Change the Name to "Kodak". Enter the Pool Name: MySQL (same as in the configuration element) Enter the SQL Query String field.

Next, add the second JDBC Request and edit the following properties

Change the Name to "Pfizer". Enter the SQL Query String field.

25

Adding a Listener to View/Store the Test Results


The final element you need to add to your Test Plan is a Listener. This element is responsible for storing all of the results of your JDBC requests in a file and presenting a visual model of the data.

Correlation in Jmeter
To remove the dynamic value of Http request correlation is used .Jmeter Script can be correlated with help of Regular expression Extractor.

Refer the Screenshot below to view the Dynamic Session_ID and Engine_ID https://www.irctc.co.in/cgi-bin/bv60.dll/irctc/booking/planner.do?screen=fromlogin& BV_SessionID= @@@@1502947175.1355111858@@@@ & {Left Boundary } Dynamic Value { Right Boundary}

26

Steps of Correlation:

1. Find the Dynamic Value in Http Request in this case Session_ID and Engine_ID are Dynamic values 2. Add Regular expression Extractor for Seesion_ID e.g : BV_SessionID=(.*?)& check number of occurrences in Regular expression tester 3. Add Regular expression Extractor for BV_EngineID e.g : BV_EngineID=(.+)"> check number of occurrences in Regular expression tester

27

4. Provide the Template and Match No e.g for First match $1$ and 1

5.

Replace BV_SessionID and BV_EngineID values with Variable ${S} and ${E}
Refer the screen Shot Below

28

Jmeter Parameterization
Parameterization is process of generalizing some user data so as to use it for multiple users , Suppose i want to the Log in the application with different set of data then i have to Parameterize the Username and Password .

Steps of Parameterization:
1. Go to the HTTP sampler where Username and Password are defined >> Change them with variable ${user} and ${password} Refer the Snapshot below

29

2. Add Config Element >> CSV data Set Config In CSV data Set Config add the variable name as defined above e.g user, password Provide CSV file Location e.g. C:/Login.csv

Refer Screenshot 2

30

5. Add Username and Password data in csv file

Apache Jmeter Advantages


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. You can also use it perform a functional test on websites, databases, LDAPs, web services etc. Apache JMeter features include: Can load and performance test many different server types: Web - HTTP, HTTPS SOAP Database via JDBC 31

LDAP JMS Mail - SMTP(S), POP3(S) and IMAP(S) Native commands or shell scripts

Complete portability and 100% Java purity. Full multithreading framework allows concurrent sampling by many threads and simultaneous sampling of different functions by separate thread groups. Careful GUI design allows faster operation and more precise timings. Caching and offline analysis/replaying of test results. Highly Extensible: Pluggable Samplers allow unlimited testing capabilities. Several load statistics may be chosen with pluggable timers. Data analysis and visualization plug-in allow great extensibility as well as personalization. Functions can be used to provide dynamic input to a test or provide data manipulation. Scriptable Samplers (Bean Shell is fully supported; and there is a sampler which supports BSFcompatible languages). Highly portable and supports 100% all the Java based apps Less scripting efforts as compared to other tools because of its user friendly GUI Simple charts and graphs sufficient for analyzing key load related statistics and resource usage monitors.

32

You might also like