Professional Documents
Culture Documents
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.
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
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
22. Click ok button again. This should return you to the browser
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. Select Thread Group 28. Number of Threads enter 5 29. Ramp up Period do not change 30. Loop Count enter 100
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
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
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.
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
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)
Adding Users
Add the Thread Group (Test plan >>Thread Group
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
17
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)
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
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.
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 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
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
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
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