You are on page 1of 46

Jmeter Training

JMeter is one of the most popular performance testing tools. This in depth course will cover the advanced topics of JMeter. This course will help the participants to

Create test plans for performance testing of web applications. Configure varying loads in a distributed environment Have a suite of repeatable and automated performance tests

We also have a shorter version of this course which runs for 1 day. This course covers the topics in more detail and also adds a few advanced topics that are not covered in the shorter version. WHAT IS JMETER?

o o o o o o

JMeter is one of the most popular tools for Performance Testing. It can be used to test the performance of Web applications Databases SOAP services Java Messaging Services (JMS) FTP, SMTP services LDAP services JMeter has a rich graphical environment which allows creation of test plans and running them in a

distributed environment to simulate load. It is open source and 100% FREE. CONTENTS 1. Overview of Performance Testing 2. Performance Testing Concepts 3. Performance Testing Types 4. Why to use performance Testing tool?

5. What is JMeter? 6. JMeter Basics


o o o o o o o
Execution modes Basic Elements (HTTP Request Defaults, HTTP Cookie Manager, HTTP Header Basic Listeners Thread Groups Timers Gaussina Random Timer Access Log Sampler

Manager, HTTP Cache Manager, HTTP Authorization Manager)

7. Building Web Application Test Plan.

8. Recording Test steps using Jmeter.

9. Customizing Test steps for

o o o o o o
10.

Dynamic server values Handling user sessions Parameterizing user sessions using csv files. Configuring with respective users numbers. Adding Cookie Support, HTTP Requests, Post-Processor for Correlation. Adding JDBC data lookup test step for simulating offline user activity. Other Resources and Load Time Images Java Scripts JMeter and HTTP headers policy Functions Using Functions Functions helper Using BeanShell Scripting Short introduction to BeanShell Creating samplers BeanShell listener BeanShell function Resource Monitoring Monitoring and analyzing CPU resources Monitoring database queries Monitoring memory utilization Running JMeter in distributed mode for load simulation. Saving the data through Simple Data Writer. How to analyze the results

o o o
11.

o o
12.

o o o o
13.

o o o

14.
15. 16.

o o o o o o o
17.

Running tests at night and creating periodical reports Statistics available from JMete Sample, Average, Median, Deviation, Throughput Response time graphs Analyzing results with Excel Interpreting statistical results Regression and correlations Other key features Stress testing a database Using JMeter from the command line Editing a test plan in a text/XML editor

o o o

HTML REPORT IN JMETER

http://jmeterworld.wordpress.com/2009/03/16/junit-sampler-tutorial-jmeter/

Generate the test report in Jmeter Posted on February 18, 2009 by Sirish behera Prerequisites: 1. Apache-ant is the Pre-requisite for generating the report from the jmx file. Apache Ant is a Java-based build tool. 2. Ant-jmeter.jar Steps: 1. Create a new variable JAVA_HOME in the environment variable and set the path for the jdk. 2. You can find the Environment variable by right clicking on the computer Icon then properties-> Advance-> environment variable. Then click on the new and give the variable name as well as path also. 3. Likewise create another variable ANT_HOME and set the path for the Apache-ant. 4. Create another variable PATH and set the path for apache-ant up to bin folder as shown in the fig. bellow.

5. Place the ant-jmeter.jar file in side Extras folder. Which is located in the path jakarta-jmeter-2.3.2->extras 6. Navigate to the build.xml folder of the jmeter which is located in the path jakarta-jmeter-2.3.2->extras>build.xml. 7. Set the classpathref = d:/jakarta-jmeter-2.3.2/extras/ant-jmeter.jar 8. Set jmeterhome=D:/jakarta-jmeter-2.3.2 9. Set style=D:/jakarta-jmeter-2.3.2/jmeter-results-detail-report${style_version}.xsl and save it. 10. Now copy your jmx file and the build.xml file put it in a folder where ever you want to generate the report. 11. Open your command prompt and navigate to the folder where your jmx and build file is located. 12. To run a test and create the output report: Type the command ant -Dtest=script(for eg. I have my test.jms file and the command is ant-Dtest=test)

It will generate an Html file. This can be open in the browser as shown in the fig. bellow.

13. To run a test only: Type the command ant -Dtest=script run 14. To run report on existing test output Type the command ant -Dtest=script report

JUnit Sampler Tutorial- JMeter Posted on March 16, 2009 by Admin JUnit sampler provides easy ways to unit test the Java applications. Each Java class that you write will correspond to a JUnit Java class that will test the methods of your class. For example if you want to test some methods of a class Book you create a classBookTest which extends the JUnit TestCase class and place your test methods in there.( i.e. Create a subclass of TestCase). In this tutorial we create a SampleTest class which has four methods. Steps: 1. Create a folder (package) mypack inside lib\junit. Put the SampleTest.java file inside it. 2. Since we are importing TestCase class we need to set the classpath for junit.jar file. SampleTest.java

package mypack; import junit.framework.TestCase; public class SampleTest extends TestCase { int a=10,b=5; int c,d,e; public void testsum() { c=a+b; System.out.println(The Sum of two numbers is: +c); } public void testmulti() { d=a*b; System.out.println(The product of two numbers is: +d); } public void testdiv() { e=a/b; System.out.println(The division of two numbers is: +e); } }

3. Compile the SampleTest.java file Cmd:\ Jmeterhome\lib\junit\mypack> javac SampleTest.java 4. Now create a jar file for the package mypack; Cmd:\Jmeterhome\lib\junit> jar cvf mytest.jar mypack Here mytest.jar is the name of the jar file that will be generated and mypack is the package name getting jarred. 5. Now since the jar file is inside junit folder Jmeter (Junit Sampler automatically detects the class). 6. Run Jmeter and add a JUnit sampler to the thread group.

Now check the Classname option in the GUI; mypack.SampleTest has been added to the list.Select any method from the test methods available.Run the test and view the result in a listener.

The command prompt will display the output of the method.

POP-UP Recording Limitation in Jmeter Posted on March 3, 2009 by Admin

There are generally three kinds of popup-1. Alert box 2. Confirm 3. Prompt. These are Client side scripts/programs generated in the webpage. Since Jmeter is build to load test Servers it cant record these popups generated during recording a site with Jmeter. The limitation has also been cited in http://jakarta.apache.org/jmeter/ These are the supported reasons for this: 1. JMeter is not a browser: JMeter is not a browser. As far as web-services and remote services are concerned, JMeter looks like a browser (or rather, multiple browsers); however JMeter does not perform all the actions supported by browsers. In particular, JMeter does not execute the Javascript found in HTML pages. Nor does it render the HTML pages as a browser does (its possible to view the response as HTML etc, but the timings are not included in any samples, and only one sample in one thread is ever viewed at a time). 2. The Proxy Server can only record HTTP traffic (any requests to server) 3. Does JMeter process dynamic pages (e.g. Javascript and applets) JMeter does not process Javascript or applets embedded in HTML pages. JMeter can download the relevant resources (some embedded resources are downloaded automatically if the correct options are set), but it does not process the HTML and execute any Javascript functions. If the page uses Javascript to build up a URL or submit a form, you can use the Proxy Recording facility to create the necessary sampler. If this is not possible, then manual inspection of the code may be needed to determine what the Javascript is doing. I have tried verifying this with two methods. In first method I recorded the pop-ups in BADBOY tool and tried to export it to Jmeter. Secondly tried it with Jmeter itself. Method1: (Exporting from BADBOY)

We record the Alert box and prompt from the below link: http://alokranjan.freehostia.com/pop/popup.html

Now we save the script. And when we try to export it the following error comes.

It says items like Messagebox and alert box are not supported in Jmeter.

Method2. (Recording in Jmeter) Site: http://alokranjan.freehostia.com/pop/popup.html

When we click on the write sth alert box it writes a line (this is a sample line) on the web page. When we record the site only the page gets recorded and .The alert box and text output doesnt get recorded.

This confirms that Jmeter cant handle popups or client side scripts.

Custom Plugins for Jmeter Posted on February 24, 2009 by Admin 1. Load Testing RMI server in Jmeter : (New RMI sampler) 2. Better Graphs in Jmeter : (Custom Listener) 3. Enhanced JDBC Sampler for Jmeter 4.Maven JMeter plugin and report generation 4. SMTP Sampler Plugin in Jmeter 5.Testing EJBs with JMeter 6.JMeter Aggregator Plugin 7. Record and playing back RMI calls (RMI Serevr) Swing Sampler in Jmeter 8.JMeter-groovy-sampler - Runs Groovy Scripts in Jmeter 9. Automate JMeter tests in Maven 10. JMeter to Nagios Like Be the first to like this post. Filed under: Uncategorized TCP Sampler- Jmeter POP-UP Recording Limitation in Jmeter

TCP Sampler- Jmeter POP-UP Recording Limitation in Jmeter 5 Responses 1.

ARN, on February 24, 2009 at 10:11 am said: For Building JMeter plug-in with Eclipse- follow this link 1.http://wiki.apache.org/jakarta-jmeter/BuildingPlugInWithEclipse for jmeter source codes http://kickjava.com/src/org.apache.jmeter.samplers.index.htm There is one more listener plugin: http://code.google.com/p/jmeter-plugins/ Now there is also a plugin to allow JMeter to report using the SNMP protocol. http://sourceforge.net/projects/snmpjmeter/ A listener to log results to a MySQL database is available: http://jmeterdbcollect.sourceforge.net/

Reply

XPath Assertion in Jmeter Posted on January 16, 2009 by Admin The XPath Assertion tests a document for well formedness, has the option of validating against a DTD, or putting the document through JTidy and testing for an XPath. If that XPath exists, the Assertion is true. Using / will match any well-formed document, and is the default XPath Expression. The assertion also supports Boolean expressions, such as count(//*error)=2. You can also go through the previous tutorial: xml assertions . Steps: 1. We record a file shiporder.xml (http://tomhanks.9ix.net/xml/shiporder.xml) and will assert if the elements and attributes are correct. The shiporder.xml file is like this. Shiporder.xml <shiporder orderid=889923 xsi:noNamespaceSchemaLocation=shiporder.xsd> <orderperson>John Smith</orderperson> <shipto> <name>Ola Nordmann</name> <address>Langgt 23</address> <city>4000 Stavanger</city> <country>Norway</country> </shipto> <item> <title>Empire Burlesque</title> <note>Special Edition</note> <quantity>1</quantity> <price>10.90</price> </item> <item> <title>Hide your heart</title> <quantity>1</quantity> <price>9.90</price> </item> </shiporder> 2. Add an XPath Assertions Element to the sample. (Add->Assertions->XPath assertions). Add Assertion results to the sample. (Add->Listener->Assertion Results).Also add a view results tree.

Now to assert an XPath we need to provide path expressions in the XPath Assertion field. Here we put /shiporder/item/note

Run the script. The result will be shown in green in the View Listener tree if the assertion is true.

Now put the XPath as: /shiporder/item[2]/note Run the script and the assertion will fail since there is no note in second item. The following message will come. Assertion failure message: No Nodes Matched /shiporder/item[2]/note

In Location Path Expression you can also use XPath Axes, functions and operators.

HTTP URL Re-writing Modifier Posted on January 2, 2009 by Admin For web applications that use URL Re-writing to store session ids instead of cookies, this element can be attached at the ThreadGroup level, much like the HTTP Cookie Manager. Simply give it the name of the session id parameter and it will find it on the page and add the argument to every request of that ThreadGroup. Correlation with HTTP URL Re-writing Modifier: To use HTTP URL Re-writing Modifier we have to record a scenario where session ids are created. This element will grab the parameter values from previous response. It will find the parameter anywhere it exists on the page, and grab the value assigned to it, whether its in an HREF or a form. Steps: 1. Record the site.

When you run the script it will show session expired in the listener. (View result tree->response data in Html rendered).The result may appear in red as failure. Check the sample which sends session ids as requests to the server. (Look in thesend parameter with request field of the sample). There are two variables- BV_SessionID and BV_EngineID. The values of these session IDs comes from the server in the previous request. So these values are sent back again to the server by the browser as request in this sample. For each run these values change. So we have to replace them dynamically. We will add HTTP URL Re-writing Modifier (pre processor) to this sample which will fetch the session ids from previous sample.

2. Select the sample. Add a HTTP URL Re-writing Modifier (add-> pre processor-> HTTP URL Re-writing Modifier). In this example there are two session ids as shown in send parameter with requestfield. Put the session Variable name (here BV_SessionID) in Session Argument Name.

Here we add another HTTP URL Re-writing Modifier for the second session ID. Dont forget to select the Cache Session Id? Option in the URL re-writing Modifier. 3. Now change the variable values to * in the sample.

4. Save and run the script. The result will be successful.

Getting Memory usage of a server in Jmeter Posted on January 27, 2009 by Admin Steps:1. The first step is to add a Thread Group element. The Thread Group tells JMeter the number of threads you want. Always use 1, since we are using JMeter as a monitor. This is very important for those not familiar with server monitors. As a general rule, using multiple threads for a single server is bad and can create significant stress. Change the loop count to forever (or some large number) so that enough samples are generated. 2. Add the HTTP Authorization Manager to the Thread Group element (Add > Config element > HTTP Authorization Manager). Enter the username and password for your webserver. Important note: the monitor only works with Tomcat5 build 5.0.19 and newer. 1. leave the base URL blank 2. enter the username 3. enter the password 3. Add the HTTP Request to the Thread Group element (Add > Sampler > HTTP Request). Then, select the HTTP Request element in the tree and edit the following properties): 1. Change the Name field to Server Status. 2. Enter the IP address or Hostname 3. Enter the port number 4. Set the Path field to /manager/status if youre using Tomcat. 5. Add a request parameter named XML in uppercase. Give it a value of true in lowercase. 6. Check Use as Monitor at the bottom of the sampler

4. Add a Constant timer to this thread group (Add > Timer > Constant Timer). Enter 5000 milliseconds in the Thread Delay box. In general, using intervals shorter than 5 seconds will add stress to your server. Find out what is an acceptable interval before you deploy the monitor in your production environment. 5. Add the Monitor Results Listener by selecting the test plan element (Add > Listener > Monitor Results). There are two tabs in the monitor results listener. The first is the Health, which displays the status of the last sample the monitor received. The second tab is Performance, which shows a historical view of the servers performance. 6. Run the test and see the result in view listener tree. The free memory and total memory is in response data for that sample. Note: If you run out of memory Negative-effect of Jmeter is they consume a lot of memory. If your JVM is running out of heap memory, you need to edit your Jmeter.bat and increase the heap memory size by editing the following line: >> HEAP=-Xms256m -Xmx1024m Change the jmeter.bat HEAP=-Xms1024m -Xmx1024m If you have a system RAM of 2GB then edit jmeter.bat to increase heap memory size Xms1536m-xmx1536m.

XML Schema assertions-Jmeter Tutorial Posted on December 29, 2008 by Admin The XML Schema Assertion allows the user to validate a response against a XML Schema. XML Schema is an XML-based alternative to DTDs. An XML Schema describes the structure of an XML document. The XML Schema language is also referred to as XML Schema Definition (XSD).Before going through this tutorial please have a brief idea on XML and XML schema. Steps: 1. We record the simple.xml file form the site (www.tomhanks.9ix.net/scripts) and validate it against simple.xsd. simple.xml <?xml version=1.0?> <person> <name> alok ranjan </name> </person>

simple.xsd <?xml version=1.0 encoding=UTF-8 ?> <xs:schema xmlns:xs=http://www.w3.org/2001/XMLSchema><xs:element name=name> <xs:complexType mixed=true /> </xs:element> <xs:element name=person> <xs:complexType> <xs:sequence> <xs:element ref=name /> </xs:sequence> </xs:complexType> </xs:element> </xs:schema> Copy the contents of simple.xsd to a notepad and save it as simple1.xsd.Place it under bin directory. You can record your own XML file and validate it against its schema. For generating the schema for a XML file we can use XSD generator tools .This can also be done online here:

http://www.hitsw.com/xml_utilites/ http://www.flame-ware.com/products/xml-2-xsd/

2. Add schema assertions to the simple.xml sample. (Add->assertions->Xml Schema assertions) 3. Now provide the path and filename of schema in XML Schema Assertion element. Here we put simple1.xsd.

Now run the script and the view the result in View results tree . If assertion is passed the result is shown in green otherwise red.To view the results add an assertions results listener to the xml sample. (Add->listener->assertions Results) By default all the failure details are shown in the assertions result tab in the view results tree. experimentation: we can tweak the schema to see what errors can be thrown by jmeter. 1. Remove the xmlns part from second line in the schema file sipmle1.xsd. The line is shortened to: <xs:schema>.Now run the script.An error comes like this: Assertion failure message : fatal: line=2 col=12 The prefix xs for element xs:schema is not bound. 2.Lets remove the fifth line i.e </xs:element>.Running the script gives following error. Assertion failure message : fatal: line=16 col=3 The element type xs:element must be terminated by the matching endtag </xs:element>

XML Assertions in Jmeter Posted on December 24, 2008 by Admin Before going through this tutorial please have a brief idea about XML. The XML Assertion tests the response data whether it consists of a formally correct XML document.So it validates the response to be a valid XML type.It does not validate the XML based on a DTD or schema.To validate the response against any schema you can use XML Schema Assertions. To use XML Assertions we have to record the XML file from the server.In this example we will be recording these files: 1. Correct XML document 2. Invalid XML document File1:Valid <?xml version=1.0?> <person> <name> <firstname>Paul</firstname> <lastname>McCartney</lastname> </name> <job>Singer</job> <gender>Male</gender> </person> File4:Invalid <?xml version=1.0?> <note> <to>Alok</to> <from>Ranjan <heading>Reminder</heading> <body>Call me today.<body> </note>

Steps: 1. Record file1 (Valid XML) and file4 (invalid XML) from this link: www.alokranjan.uuuq.com.Or you can can record any file of your own choice.

Now add XML assertions to both the sample. (Add->assertions->XML assertions).also add a View Results tree Listener. Now run the script. The result in listener will look like this.The failure is shown in red. The Assertion result is like this. Error on line 7: The element type body must be terminated by the matching end-tag </body>.

To view the assertion results we can add an assertions results listener. (Add->Listener->assertions results)

If you try to assert the response of any normal html request with XML assertions it will though a mark up error,like this:

TCP Sampler- Jmeter Posted on February 19, 2009 by Admin The TCP Sampler opens a TCP/IP connection to the specified server. It then sends the text, and waits for a response. You can test any Server working over TCP/IP. But In this example I have tested this sampler with a TCP server made in C#. You can download the TCP server here. http://alokranjan.freehostia.com/codes/TCP%20Server.zip Steps: 1. Run the TCP server on your system and create a new Test case in Jmeter. The server looks like this before any client connections.

2. Add a TCP sampler to the thread group. Fill the fields as followsServer name or IP: Localhost Check reuse connection Port number: 13000 Timeout: 200 Check Set Nodelay Text to send: This is the text i hav sent to tcp server Since there is no login request for the server we leave the username and password field blank.

3. Add a listener (View Results tree) and run the test.

The sampler result tab gives the response code and load time. The response data shows the data sent by the Server. You can also check the server whether it has sent the data or not.

FTP Sampler Jmeter Posted on February 17, 2009 by Admin This controller lets you send an FTP retrieve file or upload file request to an FTP server. If you are going to send multiple requests to the same FTP server, consider using a FTP Request Defaults Configuration Element so you do not have to enter the same information for each FTP Request Generative Controller. When downloading a file, it can be stored on disk (Local File) or in the Response Data, or both. There are many anonymous ftp sites in the web. Just search in Google as FTP sites or Anonymous FTP sites and you will get a good list of ftp sites which you can connect to. But if you are unable to connect to one of them due to firewall you can set up your own FTP Server. Download free FTP server fromwww.goldenftpserver.com/golden-ftp-server.zip and install it with default settings in your system. Share a file in your server (Open shares->Add).Also share a Folder (enable full control) in your server and name it as Add.

Select a share and click info and it will show the access path to the file.

You can connect to this file from another system of your network (if only firewall is disabled) through command prompt (ftp 172.26.3.206).Once it is connected you can check the connections to your server. In this example we are testing a server hosted in the same system. 1. Open a new Test plan in Jmeter and under add a thread group under it. Add two FTP Request Samplers to it. The first sampler is used foe retrieving a file from FTP server and second is for uploading a file to it. 2 .Give server name as localhost (you can also mention the IP).Remote file is given as it is shown in the server and local file is the name under which it will be stored after it gets retrieved. Select get(RETR) option. Enter Login Configurations as required (here anonymous/ anonymous).

Similarly for second sample configure the settings. Here Local file is the file to be uploaded in FTP server (give full path of this file).Remote file is how it will be uploaded into the server (here it will be uploaded in Add folder).Select put (STOR) option.

Now run the test and view results in Results tree listener. If the test is successful the retrieved file is stored in bin folder.

FAILURE MESSAGES: Response code: 550 Response message: 550 Operation not complete This means that the path where file is to be uploaded is not modifiable. (Should enable full control)

Webservices testing with Jmeter Posted on February 4, 2009 by Admin Webservice: Web service is a method of making various applications communicates with each other automatically over the Internet. The term Web services describes a standardized way of integrating Web-based applications using the XML, SOAP, WSDL and UDDI open standards over an Internet protocol backbone. XML is used to tag the data, SOAP is used to transfer the data, WSDL is used for describing the services available and UDDI is used for listing what services are available. Web Services have three basic platform elements: SOAP, WSDL and UDDI. SOAP (Simple Object Access Protocol): SOAP is a simple XML-based protocol to let applications exchange information over HTTP. WSDL (Web Services Description Language): WSDL is an XML-based language for describing Web services and how to access them. UDDI (Universal Description, Discovery and Integration): UDDI is a directory service where businesses can register and search for Web services. Webservice you can use: http://www.webservicex.net/ http://www.xmethods.net/ http://www.w3schools.com/webservices/tempconvert.asmx?WSDL http://www.startvbdotnet.com/web/sample2.asmx?WSDL http://www50.brinkster.com/vbfacileinpt/np.asmx?wsdl (prime number) Tutorials: http://wso2.org/library/3862 http://mattharrah.com/blog/software-development/jmeter-and-web-services-parti/ http://wso2.org/library/1085

http://javaboutique.internet.com/tutorials/JMeter/index-9.html http://www.testingminded.com/2009/01/tutorialon-testing-webservices-with.html http://www.oracle.com/technology/pub/articles/dev2arch/2006/08/jmeter-performance-testing3.html SOAP Client: http://www.soapclient.com/soaptest.html SOAPUI tool is specifically built to test webservices.

How Apache JMeter simulates multiple users? Friday, March 26, 2010 by Tushar Joshi, Nagpur Topics covered in this article: 1. 2. 3. 4. Introduction to different elements of a JMeter Test Plan. Difference between real world and JMeter world while doing a web request. Workflow of a typical web server request and response. JMeter's role in a web testing work flow.

Let us take a view at how a request for web page is sent to the Web server from a User's browser, and how a web page is finally displayed. Understanding this workflow will give us opportunity to imagine how JMeter fits in this workflow and how it can do same thing as a browser does.

Now introducing Apache JMeter into the picture. The actions taken by the User are no longer required. The User action trigger some HTTP requests which are recorded in a JMeter HTTP Request Sampler for multiple uses. See how JMetr replaces a browser, but how the working is a little different.

So what makes one User transaction in terms of JMeter?

When we add a HTTP Request Sampler in JMeter Test plan it stores one Web Page calling and receiving sequence. We can call this as a single user transaction. As soon as we tell this to JMeter it is capable of doing the same thing any number of times. It also does this multiple times simultaneously.

As JMeter is not exactly a browser the HTTP Request Sampler makes all the received data available for further analysis. We use View Tree Listener for actually visualizing the received response. View Tree Listener is a good way to know what request was sent, what was the response and the result of the transaction.

When JMeter simulates multiple users by making the same call multiple times, in different operating system threads (we can say execution paths) that time more analytical data is available. The Summary Report Listener can show us the additional calculated data line Minimum time and Maximum time taken to receive the response. It also calculates the average time taken using all the results together.

So we have seen that for web site testing we need many items like 1. 2. 3. HTTP Request Sampler View Tree Listener Summary Report Listener

To use these items provided by JMeter we will also need items like

1. 2.

Test Plan and Thread Group

For some advanced user transactions and logical conditions there are Controllers. Once we learn how to combine these elements we are ready to write our first Test Plan in JMeter.

Yes initially this may seem like a lot of jargon. Eventually we will get used to these elements and then testing will be a piece of cake. Ok, let us re-visit what they all mean in JMeter world.

We will write our first Test Plan step by step in the next article but let us first get introduced formally with the different elements we have seen till now.

Now we know some elements which will be used in creation of a Test Plan in JMeter. It will be worthwhile checking the difference between real world transactions and the transactions that happen in JMeter world. Is there one to one mapping between actions performed in real world and while executing a JMeter test plan?

Thats all for this article. Thanks for reading.

Short Interview with Apache JMeter Tuesday, March 23, 2010 by Tushar Joshi, Nagpur Quality Analyst: Hello JMeter can you tell us something about yourself? Apache JMeter: Hello! I am a load testing tool. If you tell me how to perform a certain action I can simulate multiple users doing that action. This is like cloning users, isn't it? I am a child of Apache Jakarta project, technically sub project of Apache Jakarta project. I was created initially to test performance of web sites, but you know what, now I help people test many more things like database performance, FTP server performance and much more. For more information you can visit my home page here. Quality Analyst: We heard that sometimes you talk Java and Javascript language? Is this true, and do we Quality Analysts have to know Java or JavaScript to talk with you? Apache JMeter: Well, simple scenerios of testing can be done with no knowledge of JavaScript but for advanced functional testing you should know JavaScript. Java is needed only if you are using Java Sampler part of my abilities and if you want to extend my capabilities. Quality Analyst: You mentioned functional testing just now, so can you also help us testing our software functionally? Apache JMeter: The answer is yes. I can help you test the software functionally. This requires thorough knowledge of the Sampler you are using. For example in case of web site testing HTTP Request Sampler is used so the request and response patterns of this sampler shall be known to

the user. They can then write assertions on the response to check whether the response was as expected and hence functionally check the response. Quality Analyst: Do you like a particular browser? Apache JMeter: This question is confusing. Let me clear some points first. I am not a browser. No, I am not a browser in traditional sense. Yes I can visit a web site just like a browser do (through my HTTP Request Sampler and HttpClient Sampler) but I do not show that web site on screen exactly as a browser do. My job is to visit a web site and capture the response sent by that web site. I can show you the response as TEXT, XML or even in terms of HTML but without executing any JavaScript on that page. So there is no question of me liking any browser. Browsers and I are different things. My behaviour is different than any existing browser. Quality Analyst: I know that you help us record our actions and then you can play them again. My question is, are those recordings OS dependant? In other words if I record something on Linux, can I play those actions on a Windows workstation? Apache JMeter: Oh yes you can. I can save Test Plans for you and those test plans are in XML format so they have nothing to do with any particular OS. You can run those test plans on any OS where I can run. Thanks for your time JMeter. It was nice talking with you.

Installing Apache JMeter in Windows XP Wednesday, March 17, 2010 by Tushar Joshi, Nagpur This article contains following topics:

Prerequisites for installing Apache JMeter How to install Apache JMeter? How to start Apache JMeter?

Prerequisites for installing Apache JMeter

Apache JMeter is a utility based on Java. We need Java runtime already installed to use Apache JMeter. After confirming that our Windows XP system has proper Java runtime installed we can proceed for installing Apache JMeter. For checking whether we have Java runtime installed we can follow one of the methods given

here. The second method given on that page is the easiest and that is opening a command prompt and typing the command: java -version If the command works Java is installed and you will also know the version of Java. Apache JMeter runs on a fully compliant JVM 1.4 or higher. (It is found that some early versions of Java 1.5 below update 7 do not recognize some JVM switches and hence the jmeter.bat script file needs some changes to run JMeter, described at the end of post). Steps for installing Apache JMeter The Apache JMeter Home page contains links for downloads. When we visit Apache JMeter home page the Apache Jakarta project symbol of a bird feather can be seen with introduction to JMeter.

As shown in the image below we have to select the Download Releases link from the home page.

The download page presents many options for download. Usually the suggested mirror is the best mirror but we can choose another one if the suggested mirror gives error or seems slow. For just using the tool we need only the binary release. The screen below shows the version current at the time of writing this article. The TGZ version of the binary is relatively smallest in size. Click on that link and save the download when prompted by the browser. Alternatively you can click on the ZIP version given below and use any standard UNZIP utility to extract the files.

I have saved the TGZ file and extracted the contents by using 7Zip utility for windows. After extracting the TGZ file we get a folder named jakarta-jmeter-n.n.n, where n.n.n is the version number which we downloaded. The executable script for Apache JMeter is located in the bin directory.

The screen below shows all the contents of the jmeter bin folder. Starting Apache JMeter tool

The executable script for Windows platform is jmeter.bat for Linux systems it will be jmeter.sh These scripts are used to start JMeter in GUI mode. Let us double click the jmeter.bat script to start the tool.

Double clicking the jmeter.bat file will start one command prompt and the JMeter utility in GUI mode, as shown below. The command prompt is tied with the GUI and hence cannot be closed.

If the command prompt is closed the GUI will terminate. We can keep the command prompt minimized while working with JMeter GUI. The command prompt is useful in viewing any JMeter exceptions that may occur.

We saw how to download, install and start the Apache JMeter utility. NOTE: Although Apache JMeter can run on any fully compliant Java version above Java 1.4 (It is found that some early versions of Java 1.5 below update 7 do not recognize some JVM switches and hence the jmeter.bat script file needs some changes to run JMeter. If you happen to have early Java 1.5 version below update 7 then you may get error when double clicking the jmeter.bat file. The error can be fixed by commenting line "set DUMP=-XX: +HeapDumpOnOutOfMemoryError" in the jmeter.bat file. Open the jmeter.bat file by right clicking and choosing Edit option. add REM before that line and you are ready to go. Reference: 1) http://jakarta.apache.org/jmeter/usermanual/get-started.html#install Thanks for reading.

How to Assert on HTTP Response Code in Jmeter While testing performance of web applications we would want to verify the pages are functioning as expected. But sometimes the page is too huge for the jmeter test client to download, or some times you are not concerned about the contents of the response page, rather you just want to make sure the page is

delivered, i.e. there are no 404 or 500s , but the response code is 200 OK, or redirect 302 , which ever is expected in your test scenario. solution : In the Response Assertion you should select Response Code rather than the default response, and add 200|302 if you are expecting redirect or 200 if you want to test if the page is being delivered without at issues.

Setting Cookie in Jmeter ThreadGroup HttpRequest BeanShell Pre Processor CookieManager This is what the Pre Processor should have import org.apache.jmeter.protocol.http.control.CookieManager; import org.apache.jmeter.protocol.http.control.Cookie; CookieManager manager = sampler.getCookieManager(); Cookie cookie = newCookie(<NAME>,<VALUE>,<HOST>,/,false,0); manager.add(cookie); The only reason Im using a pre processor is Im not sure how else to get the CookieManager , but I suppose there is a way . ideally Id do this in a post processor .

How to GET and SET Variables in JMeter Jmeter is very useful for testing web pages, as it helps us scrape a web page and grab stuffs you want in the web page to be used somewhere else in the script. Classic example is when you want to grab a token, or a URL which you would like to call after you call the main page for instance. My favourate way to do this is by using the Regular Expression Post processor, which allows me to provide a regular expression with the following options 1. Reference Name : This will be the name of the variable where the value extracted form the web page based on the regular expression will be stored and can be referenced elsewhere in the script 2. Regular Expression : this is the regular expression for the line to be matched 3. Template : The format to be specified is $<group_number>$ , which specifies which group will be picked up and stored in the reference name/variable. The grouping is similar to the one in Java Regular Expression, example : $2$ would result in the second of the groups to be picked up form a regular exmpression (.*)details=(.*)src=(.*) , which is the value of what ever follows details= in the regular expression 4. Match No ( 0 for Random) : 1 would specify the first occurance of a line that matches the regular expression 5. Default Value : Now once you have a Reference name of a variable , you would use it in the following way 1. You can refer to it form other SAMPLERS by using the following format ${REF_NAME} 2. Assign it to a String variable in BEAN SHELL String x = vars.get(REF_NAME); Now if you would like to re-assign value for the REFFRENCE NAME after modification in Bean Shell, you would do it as follow vars.put(REF_NAME,some_value);

How to Print Variables in JMeter I often find myself looking for this, though i very well know it. Its very useful to print variables in a Post Processor Bean shell in Jmeter, while you are developing / debugging your script. Specially when you are

using variables that are picked up from CSV files. So here is a the 2 lines you use in a Beanshell to print the variables in Jmeter. String auth = vars.get(oauth_token); System.out.println( AUTH Token = + auth);

Performance Test Results Template Test Goals Please specify the goals of the test. Its important to layout the Entry and Exitcriteria in this section. Success Criteria : [To include overall throughput goal. This also needs to account for server stats and fanout] Test Parameters

Test Scenario [e.g. Top pages/Pulse or a new test that needs to be written] Expected throughput. Initial topology Staging Production scaledown List of Service(s) under Test (SUT) : [This needs to come from the initial load test and a fanout
report] Result Summary:

Performance Statistics : * Any capacity addition or config change in production MUST be called out.
Report results as below foreach service in the fanout report [including all frontends] do Throughput achieved for each service; Incremental or total Cores required for throughput CPU Utilization Memory required GC Settings needed Healthcheck Stats reviewed and signed off threadpool,connectionpool, memcached setting, DB connection pool

Comparison with production capacity planning. Specify any incremental capacity addition needed Production/Staging capacity boost recommendation if needed. done

TEST RESULT LINK : [Hudson link to test result] This contains the details given below Throughput : Server Stats : CPU Utilization in the Service(s) under test ( good to include related components as well ) GC Stats : GC Stats for Service(s) under test ( and related components if necessary ) Full GC count GC failure count GC Throughput(%) Container Stats : Average thread pool count : Memcached stats [Optional / if necessary ] : TEST SETUP : List number of cores in test environment for each Service Under test : List number of Max threads in container for each Service Under test : TEST SETUP PROD SETUP MAPPING : STG-BETA PROD Notes Services running on the box running SUT number of servers running SUT Configuration of Servers running SUT Number of Max Threads on Container running SUT <! > Labels parameters

Functions in Jmeter Bean Shell Type of function Name Comment Information threadNum get thread number Information machineName get the local machine name Information time return current time in various formats Information log log (or display) a message (and return the value) Information logn log (or display) a message (empty return value) Input StringFromFile read a line from a file Input CSVRead read from CSV delimited file Input XPath Use an XPath expression to read from a file Calculation counter generate an incrementing number Calculation intSum add int numbers Calculation longSum add long numbers Calculation Random generate a random number Scripting BeanShell run a BeanShell script Scripting javaScript process JavaScript (Mozilla Rhino) Scripting jexl evaluate a Commons Jexl expression Properties property read a property Properties P read a property (shorthand method) Properties setProperty set a JMeter property Variables split Split a string into variables Variables V evaluate a variable name Variables eval evaluate a variable expression Variables evalVar evaluate an expression stored in a variable String regexFunction parse previous response using a regular expression String char generate Unicode char values from a list of numbers String unescape Process strings containing Java escapes (e.g. \n & \t) String unescapeHtml Decode HTML-encoded strings String escapeHtml Encode strings using HTML encoding Reference / details http://jakarta.apache.org/jmeter/usermanual/functions.html

Tip #13: Checking for empty variable using IF controller Sometimes you need to add HTTP samplers with dynamic URL or with dynamic part of the URL which are stored in some variable after HTTP sampler post-processing.

But if Regular Expression Extractor will not find any matching string result variable will be set to default value (empty value in our case). We should test this variable for emptyness before we will use it.

Now if the News page has not any news we are sure that JMeter will handle this situation correctly. Posted by Victor at 4:07 PM 0 comments Email ThisBlogThis!Share to TwitterShare to Facebook Labels: IF controller, JMeter, post-processors, regular expressions, variables WEDNESDAY, JUNE 2, 2010 Tip #12: How to add HTTP Request sampler with dynamic URL If you need to add HTTP Request sampler with dynamic URL that can be different each time from testing to testing you must use one of the Post-Processors offered by JMeter. I usually use Regular Expression Extractor for this purposes. So, let's imaging that you have "Popular News" web page which contains the links to "News Story" web pages that contains the full texts of news and you want to write a test which will include both "News" page and random "News Story" page. For this you must include "News" page HTTP Request sampler inside Simple Controller with a Regular Expression Extractor to store random "News Story" page URL to a variable:

Then use the variable with the stored random "News Story" page URL in "News Story" HTTP sampler:

Posted by Victor at 4:14 PM 5 comments Email ThisBlogThis!Share to TwitterShare to Facebook Labels: JMeter, post-processors, regular expressions TUESDAY, MARCH 23, 2010 Tip #11: Template for JMeter's recording proxy If you often need to use JMeter's recording proxy you can save your time by using templates for HTTP request filtering. Just add HTTP Proxy Server element to Workbench, than add regular expressions for URLs of your site like www\.example\.com.* to "URL Patterns to Include" list, add regular expressions for exclusion of some static HTTP requests like .*\.css$ to "URL Patterns to Exclude" list and save this template using "Save Selection As..." item of HTTP Proxy Server's context menu.

Next time you can just open this file in JMeter and you will have ready for work recording proxy. Posted by Victor at 4:34 PM 14 comments Email ThisBlogThis!Share to TwitterShare to Facebook Labels: JMeter, recording proxy, template SUNDAY, MARCH 14, 2010 Tip #10: How to add authentication to Test Plan Most of websites have user communities and allow users to do some actions like posting comments if they are authenticated on this website. Often the performance of a web page can be quite different depending on that fact if this page was visited by authenticated user or anonymous one. So we need to test theese pages by both anonymous users and authenticated ones. How to add authentication is described below. The steps are mostly similar to the steps of adding website search but have some small differencies. First record HTTP/HTTPS requests going to authentication page with login/password form in your browser and submitting this form. You will get Authentication Form Page and Authentication Process transactions.

Then you need to replace login and password parameters values by some variables like ${USER} and $ {PASSWORD} on Authentication Process HTTP request settings.

After that you need to prepare the text file where each line contains username and password separated by some delimiter character, e.g., comma and add new CSV Data Set Config element like below.

And now all next HTTP requests will be performed by authenticated users. Posted by Victor at 10:05 AM 0 comments Email ThisBlogThis!Share to TwitterShare to Facebook Labels: Authentication, CSV Data Set Config, JMeter, variables

THURSDAY, MARCH 4, 2010 Tip #9: Testing website search Almost every modern website has search feature and it must be carefully and thoroughly tested. You will know from this post how to do it using JMeter. First record necessary HTTP requests (including search page and search results page) using JMeter's recording proxy and group them into separate transactions.

Then go to HTTP Request sampler which corresponds to search results page and replace the keyword (which you used during recording) with some variable name, e.g., ${KEYWORD}.

Then prepare the list of keywords you want to use for search testing, save them to the text file and add CSV Data Set Config element to Thread Group. Specify the name of just created file and the variable name which will contain your keywords from file, e.g., KEYWORD (see above).

Now you are ready to test the search on your website.

Tip #5: How to run a test plan for a certain amount of time If you want to run your Test Plan for a certain amount of time instead of a certain amount of iterations you can do it in two ways:

by specifiing testing duration on the Thread Group GUI (Scheduler checkbox must be checked). Note that you must specify the value of Startup delay option as zero otherwise you will need to specify Start Time option value before each test running. And of course you need to check Forever checkbox of Loop Count option. There is 10 minutes test example on the screenshot below.

by creating extra Thread Group with two Test Action samplers. The first Test Action configured as pause, and the seconf one is configured to stop all treads. Look at the screenshots below for 10 minutes test example.

Posted by Victor at 11:27 PM 5 comments Email ThisBlogThis!Share to TwitterShare to Facebook Labels: duration, JMeter, pause, Scheduler, Test Action, Test plan THURSDAY, JANUARY 21, 2010 Tip #3: Pauses in test plan For complete user simulation you need to add pause after each transaction. In most cases you will use only two types of pauses:

1.

Constant pause. Just add Test Action controller after the Transaction controller. Specify the pause duration in ms and be sure that "Pause" item of "Action" option is checked.

2.

Variable pause. Add Test Action as described above but specify the pause duration as 0 (zero). Then add Uniform Random Timer as a child of Test Action and specify the minimum value and maximum offset value.

Tip #13: Checking for empty variable using IF controller Sometimes you need to add HTTP samplers with dynamic URL or with dynamic part of the URL which are stored in some variable after HTTP sampler post-processing.

But if Regular Expression Extractor will not find any matching string result variable will be set to default value (empty value in our case). We should test this variable for emptyness before we will use it.

Now if the News page has not any news we are sure that JMeter will handle this situation correctly. Posted by Victor at 4:07 PM 0 comments Email ThisBlogThis!Share to TwitterShare to Facebook Labels: IF controller, JMeter, post-processors, regular expressions, variables WEDNESDAY, JUNE 2, 2010 Tip #12: How to add HTTP Request sampler with dynamic URL If you need to add HTTP Request sampler with dynamic URL that can be different each time from testing to testing you must use one of the Post-Processors offered by JMeter. I usually use Regular Expression Extractor for this purposes. So, let's imaging that you have "Popular News" web page which contains the links to "News Story" web pages that contains the full texts of news and you want to write a test which will include both "News" page and random "News Story" page. For this you must include "News" page HTTP Request sampler inside Simple Controller with a Regular Expression Extractor to store random "News Story" page URL to a variable:

Then use the variable with the stored random "News Story" page URL in "News Story" HTTP sampler:

Tip #5: How to run a test plan for a certain amount of time If you want to run your Test Plan for a certain amount of time instead of a certain amount of iterations you can do it in two ways:

by specifiing testing duration on the Thread Group GUI (Scheduler checkbox must be checked). Note that you must specify the value of Startup delay option as zero otherwise you will need to specify Start Time option value before each test running. And of course you need to check Forever checkbox of Loop Count option. There is 10 minutes test example on the screenshot below.

by creating extra Thread Group with two Test Action samplers. The first Test Action configured as pause, and the seconf one is configured to stop all treads. Look at the screenshots below for 10 minutes test example.

You might also like