]>
Samplers perform the actual work of JMeter.
Each sampler (except Test Action) generates one or more sample results.
The sample results have various attributes (success/fail, elapsed time, data size etc) and can be viewed in the various listeners.
Latency is set to the time it takes to login (versions of JMeter after 2.3.1).
This sampler lets you send an HTTP/HTTPS request to a web server. It
also lets you control whether or not JMeter parses HTML files for images and
other embedded resources and sends HTTP requests to retrieve them.
The following types of embedded resource are retrieved:
The default parser is htmlparser.
This can be changed by using the property "htmlparser.classname" - see jmeter.properties for details.
If you are going to send multiple requests to the same web server, consider
using an Or, instead of manually adding HTTP Requests, you may want to use
JMeter's There are three versions of the sampler:
The default (Java) implementation has some limitations:
Note: the FILE protocol is intended for testing puposes only. It is handled by the same code regardless of which HTTP Sampler is used.
If the request requires server or proxy login authorization (i.e. where a browser would create a pop-up dialog box),
you will also have to add an
In versions of JMeter up to 2.2, only a single SSL context was used for all threads and samplers. This did not generate the proper load for multiple users. A separate SSL context is now used for each thread. To revert to the original behaviour, set the JMeter property:
https.sessioncontext.shared=true
JMeter defaults to the SSL protocol level TLS. If the server needs a different level, e.g. SSLv3, change the JMeter property, for example:
https.default.protocol=SSLv3
JMeter also allows one to enable additional protocols, by changing the property https.socket.protocols.
If the request uses cookies, then you will also need an
If the request uses a technique called "URL Rewriting" to maintain sessions, then see section 6.1 Handling User Sessions With URL Rewriting for additional configuration steps.
Additionally, you can specify whether each parameter should be URL encoded. If you are not sure what this means, it is probably best to select it. If your values contain characters such as & or spaces, or question marks, then encoding is usually required.
If it is a POST or PUT request and there is a single file whose 'name' attribute (below) is omitted, then the file is sent as the entire body of the request, i.e. no wrappers are added. This allows arbitrary bodies to be sent. This functionality is present for POST requests after version 2.2, and also for PUT requests after version 2.3. See below for some further information on parameter handling.
N.B. when using Automatic Redirection, cookies are only sent for the initial URL. This can cause unexpected behaviour for web-sites that redirect to a local server. E.g. if www.example.com redirects to www.example.co.uk. In this case the server will probably return cookies for both URLs, but JMeter will only see the cookies for the last host, i.e. www.example.co.uk. If the next request in the test plan uses www.example.com, rather than www.example.co.uk, it will not get the correct cookies. Likewise, Headers are sent for the initial request, and won't be sent for the redirect. This is generally only a problem for manually created test plans, as a test plan created using a recorder would continue from the redirected URL.
Parameter Handling:
For the POST and PUT method, if there is no file to send, and the name(s) of the parameter(s) are omitted,
then the body is created by concatenating all the value(s) of the parameters.
This allows arbitrary bodies to be sent.
The values are encoded if the encoding flag is set (versions of JMeter after 2.3).
See also the MIME Type above how you can control the content-type request header that is sent.
For other methods, if the name of the parameter is missing,
then the parameter is ignored. This allows the use of optional parameters defined by variables.
(versions of JMeter after 2.3)
Method Handling:
The POST and PUT request methods work similarly, except that the PUT method does not support multipart requests.
The PUT method body must be provided as one of the following:
Upto and including JMeter 2.1.1, only responses with the content-type "text/html" were scanned for embedded resources. Other content-types were assumed to be something other than HTML. JMeter 2.1.2 introduces the a new property HTTPResponse.parsers, which is a list of parser ids, e.g. htmlParser and wmlParser. For each id found, JMeter checks two further properties:
See jmeter.properties file for the details of the settings. If the HTTPResponse.parser property is not set, JMeter reverts to the previous behaviour, i.e. only text/html responses will be scanned
Emulating slow connections:# Define characters per second > 0 to emulate slow connections #httpclient.socket.http.cps=0 #httpclient.socket.https.cps=0
This sampler lets you send an JDBC Request (an SQL query) to a database.
Before using this you need to set up a
If the Variable Names list is provided, then for each row returned by a Select statement, the variables are set up
with the value of the corresponding column (if a variable name is provided), and the count of rows is also set up.
For example, if the Select statement returns 2 rows of 3 columns, and the variable list is A,,C,
then the following variables will be set up:
A_#=2 (number of rows) A_1=column 1, row 1 A_2=column 1, row 2 C_#=2 (number of rows) C_1=column 3, row 1 C_2=column 3, row 2If the Select statement returns zero rows, then the A_# and C_# variables would be set to 0, and no other variables would be set.
Old variables are cleared if necessary - e.g. if the first select retrieves 6 rows and a second select returns only 3 rows, the additional variables for rows 4, 5 and 6 will be removed.
"Dbl-Quote: "" and Comma: ,"There must be as many values as there are placeholders in the statement.
This sampler lets you control a java class that implements the JavaSamplerClient interface. By writing your own implementation of this interface, you can use JMeter to harness multiple threads, input parameter control, and data collection.
The pull-down menu provides the list of all such implementations found by JMeter in its classpath. The parameters can then be specified in the table below - as defined by your implementation. Two simple examples (JavaTest and SleepTest) are provided.
The JavaTest example sampler can be useful for checking test plans, because it allows one to set values in almost all the fields. These can then be used by Assertions, etc. The fields allow variables to be used, so the values of these can readily be seen.
The sleep time is calculated as follows:
SleepTime is in milliseconds SleepMask is used to add a "random" element to the time: totalSleepTime = SleepTime + (System.currentTimeMillis() % SleepMask)
This sampler lets you send a SOAP request to a webservice. It can also be used to send XML-RPC over HTTP. It creates an HTTP POST request, with the specified XML as the POST content. To change the "Content-type" from the default of "text/xml", use a HeaderManager. Note that the sampler will use all the headers from the HeaderManager. If a SOAP action is specified, that will override any SOAPaction in the HeaderManager. The primary difference between the soap sampler and webservice sampler, is the soap sampler uses raw post and does not require conformance to SOAP 1.1.
This sampler has been tested with IIS Webservice running .NET 1.0 and .NET 1.1. It has been tested with SUN JWSDP, IBM webservices, Axis and gSoap toolkit for C/C++. The sampler uses Apache SOAP driver to serialize the message and set the header with the correct SOAPAction. Right now the sampler doesn't support automatic WSDL handling, since Apache SOAP currently does not provide support for it. Both IBM and SUN provide WSDL drivers. There are 3 options for the post data: text area, external file, or directory. If you want the sampler to randomly select a message, use the directory. Otherwise, use the text area or a file. The if either the file or path are set, it will not use the message in the text area. If you need to test a soap service that uses different encoding, use the file or path. If you paste the message in to text area, it will not retain the encoding and will result in errors. Save your message to a file with the proper encoding, and the sampler will read it as java.io.FileInputStream.
An important note on the sampler is 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. This behavior may not be what users expect.
By default, the webservice sampler sets SOAPHTTPConnection.setMaintainSession (true). If you need to maintain the session, add a blank Header Manager. The sampler uses the Header Manager to store the SOAPHTTPConnection object, since the version of apache soap does not provide a easy way to get and set the cookies.
Note: If you are using CSVDataSet, do not check "Memory Cache". If memory cache is checked, it will not iterate to the next value. That means all the requests will use the first value.
Make sure you use <soap:Envelope rather than <Envelope. For example:
<?xml version="1.0" encoding="utf-8"?> <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> <soap:Body> <foo xmlns="http://clients-xlmns"/> </soap:Body> </soap:Envelope>
If you are going to send multiple requests to the same LDAP server, consider
using an
There are two ways to create test cases for testing an LDAP Server.
There are four test scenarios of testing LDAP. The tests are given below:
This will add a pre-defined entry in the LDAP Server and calculate the execution time. After execution of the test, the created entry will be deleted from the LDAP Server.
This will add the entry in the LDAP Server. User has to enter all the attributes in the table.The entries are collected from the table to add. The execution time is calculated. The created entry will not be deleted after the test.
This will create a pre-defined entry first, then will modify the created entry in the LDAP Server.And calculate the execution time. After execution of the test, the created entry will be deleted from the LDAP Server.
This will modify the entry in the LDAP Server. User has to enter all the attributes in the table. The entries are collected from the table to modify. The execution time is calculated. The entry will not be deleted from the LDAP Server.
This will create the entry first, then will search if the attributes are available. It calculates the execution time of the search query. At the end of the execution,created entry will be deleted from the LDAP Server.
This will search the user defined entry(Search filter) in the Search base (again, defined by the user). The entries should be available in the LDAP Server. The execution time is calculated.
This will create a pre-defined entry first, then it will be deleted from the LDAP Server. The execution time is calculated.
This will delete the user-defined entry in the LDAP Server. The entries should be available in the LDAP Server. The execution time is calculated.
If you are going to send multiple requests to the same LDAP server, consider
using an
There are nine test operations defined. These operations are given below:
Any LDAP request is part of an LDAP session, so the first thing that should be done is starting a session to the LDAP server. For starting this session a thread bind is used, which is equal to the LDAP "bind" operation. The user is requested to give a username (Distinguished name) and password, which will be used to initiate a session. When no password, or the wrong password is specified, an anonymous session is started. Take care, omitting the password will not fail this test, a wrong password will.
This is simply the operation to end a session. It is equal to the LDAP "unbind" operation.
This is a combination of the LDAP "bind" and "unbind" operations. It can be used for an authentication request/password check for any user. It will open an new session, just to check the validity of the user/password combination, and end the session again.
This is the LDAP "moddn" operation. It can be used to rename an entry, but also for moving an entry or a complete subtree to a different place in the LDAP tree.
This is the ldap "add" operation. It can be used to add any kind of object to the LDAP server.
This is the LDAP "delete" operation, it can be used to delete an object from the LDAP tree
This is the LDAP "search" operation, and will be used for defining searches.
This is the LDAP "modify" operation. It can be used to modify an object. It can be used to add, delete or replace values of an attribute.
This is the LDAP "compare" operation. It can be used to compare the value of a given attribute with some already known value. In reality this is mostly used to check whether a given person is a member of some group. In such a case you can compare the DN of the user as a given value, with the values in the attribute "member" of an object of the type groupOfNames. If the compare operation fails, this test fails with errorcode 49.
AccessLogSampler was designed to read access logs and generate http requests. For those not familiar with the access log, it is the log the webserver maintains of every request it accepted. This means the every image and html file. The current implementation is complete, but some features have not been enabled. There is a filter for the access log parser, but I haven't figured out how to link to the pre-processor. Once I do, changes to the sampler will be made to enable that functionality.
Tomcat uses the common format for access logs. This means any webserver that uses the common log format can use the AccessLogSampler. Server that use common log format include: Tomcat, Resin, Weblogic, and SunOne. Common log format looks like this:
127.0.0.1 - - [21/Oct/2003:05:37:21 -0500] "GET /index.jsp?%2Findex.jsp= HTTP/1.1" 200 8343
The current implemenation of the parser only looks at the text within the quotes. Everything else is stripped out and igored. For example, the response code is completely ignored by the parser. For the future, it might be nice to filter out entries that do not have a response code of 200. Extending the sampler should be fairly simple. There are two interfaces you have to implement.
org.apache.jmeter.protocol.http.util.accesslog.LogParser
org.apache.jmeter.protocol.http.util.accesslog.Generator
The current implementation of AccessLogSampler uses the generator to create a new
HTTPSampler. The servername, port and get images are set by AccessLogSampler. Next,
the parser is called with integer 1, telling it to parse one entry. After that,
HTTPSampler.sample() is called to make the request.
The required methods in LogParser are: setGenerator(Generator) and parse(int).
Classes implementing Generator interface should provide concrete implementation
for all the methods. For an example of how to implement either interface, refer to
StandardGenerator and TCLogParser.
samp = (HTTPSampler) GENERATOR.generateRequest();
samp.setDomain(this.getDomain());
samp.setPort(this.getPort());
samp.setImageParser(this.isImageParser());
PARSER.parse(1);
res = samp.sample();
res.setSampleLabel(samp.toString());
The TCLogParser processes the access log independently for each thread. The SharedTCLogParser and OrderPreservingLogParser share access to the file, i.e. each thread gets the next entry in the log.
The SessionFilter is intended to handle Cookies across threads. It does not filter out any entries, but modifies the cookie manager so that the cookies for a given IP are processed by a single thread at a time. If two threads try to process samples from the same client IP address, then one will be forced to wait until the other has completed.
The LogFilter is intended to allow access log entries to be filtered by filename and regex, as well as allowing for the replacement of file extensions. However, it is not currently possible to configure this via the GUI, so it cannot really be used.
This sampler allows you to write a sampler using the BeanShell scripting language.
For full details on using BeanShell, please see the BeanShell web-site at http://www.beanshell.org/.
The test element supports the ThreadListener and TestListener methods. These should be defined in the initialisation file. See the file BeanShellListeners.bshrc for example definitions.
N.B. Each Sampler instance has its own BeanShell interpeter, and Samplers are only called from a single thread
If the property "beanshell.sampler.init" is defined, it is passed to the Interpreter as the name of a sourced file. This can be used to define common methods and variables. There is a sample init file in the bin directory: BeanShellSampler.bshrc.
If a script file is supplied, that will be used, otherwise the script will be used.
Before invoking the script, some variables are set up in the BeanShell interpreter:
The contents of the Parameters field is put into the variable "Parameters". The string is also split into separate tokens using a single space as the separator, and the resulting list is stored in the String array bsh.args.
The full list of BeanShell variables that is set up is as follows:
When the script completes, control is returned to the Sampler, and it copies the contents of the following script variables into the corresponding variables in the SampleResult:
The SampleResult ResponseData is set from the return value of the script. Since version 2.1.2, if the script returns null, it can set the response directly, by using the method SampleResult.setResponseData(data), where data is either a String or a byte array. The data type defaults to "text", but can be set to binary by using the method SampleResult.setDataType(SampleResult.BINARY).
The SampleResult variable gives the script full access to all the fields and methods in the SampleResult. For example, the script has access to the methods setStopThread(boolean) and setStopTest(boolean). Here is a simple (not very useful!) example script:
if (bsh.args[0].equalsIgnoreCase("StopThread")) {
log.info("Stop Thread detected!");
SampleResult.setStopThread(true);
}
return "Data from sample with Label "+Label;
//or, since version 2.1.2
SampleResult.setResponseData("My data");
return null;
Another example:
ensure that the property beanshell.sampler.init=BeanShellSampler.bshrc is defined in jmeter.properties.
The following script will show the values of all the variables in the ResponseData field:
return getVariables();
For details on the methods available for the various classes (JMeterVariables, SampleResult etc) please check the Javadoc or the source code. Beware however that misuse of any methods can cause subtle faults that may be difficult to find ...
This sampler allows you to write a sampler using a BSF scripting language.
See the Apache Bean Scripting Framework
website for details of the languages supported.
You may need to download the appropriate jars for the language; they should be put in the JMeter lib directory.
By default, JMeter supports the following languages:
If a script file is supplied, that will be used, otherwise the script will be used.
Before invoking the script, some variables are set up. Note that these are BSF variables - i.e. they can be used directly in the script.
The SampleResult ResponseData is set from the return value of the script. If the script returns null, it can set the response directly, by using the method SampleResult.setResponseData(data), where data is either a String or a byte array. The data type defaults to "text", but can be set to binary by using the method SampleResult.setDataType(SampleResult.BINARY).
The SampleResult variable gives the script full access to all the fields and methods in the SampleResult. For example, the script has access to the methods setStopThread(boolean) and setStopTest(boolean).
Unlike the Beanshell Sampler, the BSF Sampler does not set the ResponseCode, ResponseMessage and sample status via script variables. Currently the only way to changes these is via the SampleResult methods:
The TCP Sampler opens a TCP/IP connection to the specified server.
It then sends the text, and waits for a response.
If "Re-use connection" is selected, connections are shared between Samplers in the same thread,
provided that the exact same host name string and port are used.
Different hosts/port combinations will use different connections, as will different threads.
If an error is detected - or "Re-use connection" is not selected - the socket is closed.
Another socket will be reopened on the next sample.
The following properties can be used to control its operation:
Users can provide their own implementation. The class must extend org.apache.jmeter.protocol.tcp.sampler.TCPClient.
The following implementations are currently provided.
TCPClientImpl
This implementation is fairly basic.
When reading the response, it reads until the end of line byte, if this is defined
by setting the property tcp.eolByte, otherwise until the end of the input stream.
BinaryTCPClientImpl
This implementation converts the GUI input, which must be a hex-encoded string, into binary,
and performs the reverse when reading the response.
When reading the response, it reads until the end of message byte, if this is defined
by setting the property tcp.BinaryTCPClient.eomByte, otherwise until the end of the input stream.
LengthPrefixedBinaryTCPClientImpl
This implementation extends BinaryTCPClientImpl by prefixing the binary message data with a binary length byte.
The length prefix defaults to 2 bytes.
This can be changed by setting the property tcp.binarylength.prefix.length.
Timeout handling If the timeout is set, the read will be terminated when this expires. So if you are using an eolByte/eomByte, make sure the timeout is sufficiently long, otherwise the read will be terminated early.
Response handling
If tcp.status.prefix is defined, then the response message is searched for the text following
that up to the suffix. If any such text is found, it is used to set the response code.
The response message is then fetched from the properties file (if provided).
For example, if the prefix = "[" and the suffix = "]", then the following repsonse:
[J28] XI123,23,GBP,CR
would have the response code J28.
Response codes in the range "400"-"499" and "500"-"599" are currently regarded as failures;
all others are successful. [This needs to be made configurable!]
JMS Publisher will publish messages to a given pub/sub topic. For those not familiar with JMS, it is the J2EE specification for messaging. There are numerous JMS servers on the market and several open source options.
JMS Publisher will subscribe to messages in a given pub/sub topic. For those not familiar with JMS, it is the J2EE specification for messaging. There are numerous JMS servers on the market and several open source options.
This sampler sends and optionally receives JMS Messages through point-to-point connections (queues). It is different from pub/sub messages and is generally used for handling transactions.
Versions of JMeter after 2.3.2 use the properties java.naming.security.[principal|credentials] - if present - when creating the Queue Connection. If this behaviour is not desired, set the JMeter property JMSSampler.useSecurity.properties=false
The Mail Reader Sampler can read (and optionally delete) mail messages using POP3(S) or IMAP(S) protocols.
This sampler can also be useful in conjunction with the Transaction Controller, as it allows pauses to be included without needing to generate a sample. For variable delays, set the pause time to zero, and add a Timer as a child.
The "Stop" action stops the thread or test after completing any samples that are in progress.
The "Stop Now" action stops the test without waiting for samples to complete; it will interrupt any active samples.
If some threads fail to stop within the 5 second time-limit, a message will be displayed in GUI mode.
You can try using the Stop command to see if this will stop the threads, but if not, you should exit JMeter.
In non-GUI mode, JMeter will exit if some threads fail to stop within the 5 second time limit.
[This can be changed using the JMeter property jmeterengine.threadstop.wait]
The Simple Logic Controller lets you organize your Samplers and other Logic Controllers. Unlike other Logic Controllers, this controller provides no functionality beyond that of a storage device.
Download this example (see Figure 6). In this example, we created a Test Plan that sends two Ant HTTP requests and two Log4J HTTP requests. We grouped the Ant and Log4J requests by placing them inside Simple Logic Controllers. Remember, the Simple Logic Controller has no effect on how JMeter processes the controller(s) you add to it. So, in this example, JMeter sends the requests in the following order: Ant Home Page, Ant News Page, Log4J Home Page, Log4J History Page. Note, the File Reporter is configured to store the results in a file named "simple-test.dat" in the current directory.
If you add Generative or Logic Controllers to a Loop Controller, JMeter will loop through them a certain number of times, in addition to the loop value you specified for the Thread Group. For example, if you add one HTTP Request to a Loop Controller with a loop count of two, and configure the Thread Group loop count to three, JMeter will send a total of 2 * 3 = 6 HTTP Requests.
Special Case: The Loop Controller embedded in the Thread Group element behaves slightly differently. Unless set to forever, it stops the test after the given number of iterations have been done.
Download this example (see Figure 4). In this example, we created a Test Plan that sends a particular HTTP Request only once and sends another HTTP Request five times.
We configured the Thread Group for a single thread and a loop count value of one. Instead of letting the Thread Group control the looping, we used a Loop Controller. You can see that we added one HTTP Request to the Thread Group and another HTTP Request to a Loop Controller. We configured the Loop Controller with a loop count value of five.
JMeter will send the requests in the following order: Home Page, News Page, News Page, News Page, News Page, and News Page. Note, the File Reporter is configured to store the results in a file named "loop-test.dat" in the current directory.
The Once Only Logic Controller tells JMeter to process the controller(s) inside it only once, and pass over any requests under it during further iterations through the test plan.
The Once Only Controller will now execute always during the first iteration of any looping parent controller. Thus, if the Once Only Controller is placed under a Loop Controller specified to loop 5 times, then the Once Only Controller will execute only on the first iteration through the Loop Controller (ie, every 5 times). Note this means the Once Only Controller will still behave as previously expected if put under a Thread Group (runs only once per test), but now the user has more flexibility in the use of the Once Only Controller.
For testing that requires a login, consider placing the login request in this controller since each thread only needs to login once to establish a session.
Download this example (see Figure 5). In this example, we created a Test Plan that has two threads that send HTTP request. Each thread sends one request to the Home Page, followed by three requests to the Bug Page. Although we configured the Thread Group to iterate three times, each JMeter thread only sends one request to the Home Page because this request lives inside a Once Only Controller.
Each JMeter thread will send the requests in the following order: Home Page, Bug Page, Bug Page, Bug Page. Note, the File Reporter is configured to store the results in a file named "loop-test.dat" in the current directory.
If you add Generative or Logic Controllers to an Interleave Controller, JMeter will alternate among each of the other controllers for each loop iteration.
Download this example (see Figure 1). In this example, we configured the Thread Group to have two threads and a loop count of five, for a total of ten requests per thread. See the table below for the sequence JMeter sends the HTTP Requests.
| Loop Iteration | Each JMeter Thread Sends These HTTP Requests |
|---|---|
| 1 | News Page |
| 1 | Log Page |
| 2 | FAQ Page |
| 2 | Log Page |
| 3 | Gump Page |
| 3 | Log Page |
| 4 | Because there are no more requests in the controller, JMeter starts over and sends the first HTTP Request, which is the News Page. |
| 4 | Log Page |
| 5 | FAQ Page |
| 5 | Log Page |
Download another example (see Figure 2). In this example, we configured the Thread Group to have a single thread and a loop count of eight. Notice that the Test Plan has an outer Interleave Controller with two Interleave Controllers inside of it.
The outer Interleave Controller alternates between the two inner ones. Then, each inner Interleave Controller alternates between each of the HTTP Requests. Each JMeter thread will send the requests in the following order: Home Page, Interleaved, Bug Page, Interleaved, CVS Page, Interleaved, and FAQ Page, Interleaved. Note, the File Reporter is configured to store the results in a file named "interleave-test2.dat" in the current directory.
If the two interleave controllers under the main interleave controller were instead simple controllers, then the order would be: Home Page, CVS Page, Interleaved, Bug Page, FAQ Page, Interleaved. However, if "ignore sub-controller blocks" was checked on the main interleave controller, then the order would be: Home Page, Interleaved, Bug Page, Interleaved, CVS Page, Interleaved, and FAQ Page, Interleaved.
The Random Logic Controller acts similarly to the Interleave Controller, except that instead of going in order through its sub-controllers and samplers, it picks one at random at each pass.
The Random Order Controller is much like a Simple Controller in that it will execute each child element at most once, but the order of execution of the nodes will be random.
This controller is badly named, as it does not control throughput.
Please refer to the
The Throughput Controller allows the user to control how often it is executed. There are two modes - percent execution and total executions. Percent executions causes the controller to execute a certain percentage of the iterations through the test plan. Total executions causes the controller to stop executing after a certain number of executions have occurred. Like the Once Only Controller, this setting is reset when a parent Loop Controller restarts.
The Runtime Controller controls how long its children are allowed to run.
The If Controller allows the user to control whether the test elements below it (its children) are run or not.
Prior to JMeter 2.3RC3, the condition was evaluated for every runnable element contained in the controller. This sometimes caused unexpected behaviour, so 2.3RC3 was changed to evaluate the condition only once on initial entry. However, the original behaviour is also useful, so versions of JMeter after 2.3RC4 have an additional option to select the original behaviour.
Versions of JMeter after 2.3.2 allow the script to be processed as a variable expression, rather than requiring Javascript.
It was always possible to use functions and variables in the Javascript condition, so long as they evaluated to "true" or "false";
now this can be done without the overhead of using Javascript as well. For example, previously one could use the condition:
${__jexl(${VAR} == 23)} and this would be evaluated as true/false, the result would then be passed to Javascript
which would then return true/false. If the Variable Expression option is selected, then the expression is evaluated
and compared with "true", without needing to use Javascript.
Also, variable expressions can return any value, whereas the
Javascript condition must return "true"/"false" or an error is logged.
${FOUND} or ${__jexl(${VAR} > 100)}.
Unlike the Javascript case, the condition is only checked to see if it matches "true" (case is ignored).
Examples (Javascript):
Examples (Variable Expression):
The While Controller runs its children until the condition is "false".
Possible condition values:
The Switch Controller acts like the
Note: In versions of JMeter after 2.3.1, the switch value can also be a name.
If the switch value is out of range, it will run the zeroth element, which therefore acts as the default for the numeric case. It also runs the zeroth element if the value is the empty string.
If the value is non-numeric (and non-empty), then the Switch Controller looks for the element with the same name (case is significant). If none of the names match, then the element named "default" (case not significant) is selected. If there is no default, then no element is selected, and the controller will not run anything.
A ForEach controller loops through the values of a set of related variables. When you add samplers (or controllers) to a ForEach controller, every sample sample (or controller) is executed one or more times, where during every loop the variable has a new value. The input should consist of several variables, each extended with an underscore and a number. Each such variable must have a value. So for example when the input variable has the name inputVar, the following variables should have been defined:
Note: the "_" separator is now optional.
When the return variable is given as "returnVar", the collection of samplers and controllers under the ForEach controller will be executed 4 consecutive times, with the return variable having the respective above values, which can then be used in the samplers.It is especially suited for running with the regular expression post-processor. This can "create" the necessary input variables out of the result data of a previous request. By omitting the "_" separator, the ForEach Controller can be used to loop through the groups by using the input variable refName_g, and can also loop through all the groups in all the matches by using an input variable of the form refName_${C}_g, where C is a counter variable.
Download this example (see Figure 7). In this example, we created a Test Plan that sends a particular HTTP Request only once and sends another HTTP Request to every link that can be found on the page.
We configured the Thread Group for a single thread and a loop count value of one. You can see that we added one HTTP Request to the Thread Group and another HTTP Request to the ForEach Controller.
After the first HTTP request, a regular expression extractor is added, which extracts all the html links out of the return page and puts them in the inputVar variable
In the ForEach loop, a HTTP sampler is added which requests all the links that were extracted from the first returned HTML page.
Here is another example you can download. This has two Regular Expressions and ForEach Controllers. The first RE matches, but the second does not match, so no samples are run by the second ForEach Controller
The Thread Group has a single thread and a loop count of two.
Sample 1 uses the JavaTest Sampler to return the string "a b c d".
The Regex Extractor uses the expression (\w)\s which matches a letter followed by a space, and returns the letter (not the space). Any matches are prefixed with the string "inputVar".
The ForEach Controller extracts all variables with the prefix "inputVar_", and executes its sample, passing the value in the variable "returnVar". In this case it will set the variable to the values "a" "b" and "c" in turn.
The For 1 Sampler is another Java Sampler which uses the return variable "returnVar" as part of the sample Label and as the sampler Data.
Sample 2, Regex 2 and For 2 are almost identical, except that the Regex has been changed to "(\w)\sx", which clearly won't match. Thus the For 2 Sampler will not be run.
The Module Controller provides a mechanism for substituting test plan fragments into the current test plan at run-time.
A test plan fragment consists of a Controller and all the test elements (samplers etc) contained in it.
The fragment can be located in any Thread Group, or on the
There can be multiple fragments, each with a different series of samplers under them. The module controller can then be used to easily switch between these multiple test cases simply by choosing the appropriate controller in its drop down box. This provides convenience for running many alternate test plans quickly and easily.
A fragment name is made up of the Controller name and all its parent names. For example:
Test Plan / Protocol: JDBC / Control / Interleave Controller (Module1)Any fragments used by the Module Controller must have a unique name, as the name is used to find the target controller when a test plan is reloaded. For this reason it is best to ensure that the Controller name is changed from the default - as shown in the example above - otherwise a duplicate may be accidentally created when new elements are added to the test plan.
The include controller is designed to use an external jmx file. To use it, add samples to a simple controller, then save the simple controller as a jmx file. The file can then be used in a test plan. The included test plan must not include a Thread Group. It should only contain the Simple Controller and any samplers, controllers etc below it.
If the test uses a Cookie Manager or User Defined Variables, these should be placed in the top-level test plan, not the included file, otherwise they are not guaranteed to work.
The Transaction Controller generates an additional sample which measures the overall time taken to perform the nested test elements. Note that this time includes all processing within the controller scope, not just the samples.
For JMeter versions after 2.3, there are two modes of operation
The generated sample time includes all the times for the nested samplers, and any timers etc. Depending on the clock resolution, it may be slightly longer than the sum of the individual samplers plus timers. The clock might tick after the controller recorded the start time but before the first sample starts. Similarly at the end.
The generated sample is only regarded as successful if all its sub-samples are successful.
In parent mode, the individual samples can still be seen in the Tree View Listener, but no longer appear as separate entries in other Listeners. Also, the sub-samples do not appear in CSV log files, but they can be saved to XML files.
The Recording Controller is a place holder indicating where the proxy server should
record samples to. During test run, it has no effect, similar to the Simple Controller. But during
recording using the
Note that Listeners are processed at the end of the scope in which they are found.
The saving and reading of test results is generic. The various listeners have a panel whereby one can specify the file to which the results will be written (or read from). By default, the results are stored as XML files, typically with a ".jtl" extension. Storing as CSV is the most efficient option, but is less detailed than XML (the other available option).
Listeners do not process sample data in non-GUI mode, but the raw data will be saved if an output file has been configured. In order to analyse the data generated by a non-GUI test run, you need to load the file into the appropriate Listener.
Versions of JMeter up to 2.3.2 used to clear any current data before loading the new file.
This is no longer done, thus allowing files to be merged.
If the previous behaviour is required,
use the menu item Run/Clear (Ctrl+Shift+E) or Run/Clear All (Ctrl+E) before loading the file.
Results can be read from XML or CSV format files. When reading from CSV results files, the header (if present) is used to determine which fields are present. In order to interpret a header-less CSV file correctly, the appropriate properties must be set in jmeter.properties.
Listeners can use a lot of memory if there are a lot of samples. Most of the listeners currently keep a copy of every sample in their scope, apart from:
To minimise the amount of memory needed, use the Simple Data Writer, and use the CSV format.
The figure below shows an example of the result file configuration panel
Listeners can be configured to save different items to the result log files (JTL) by using the Config popup as shown below. The defaults are defined as described in the Listener Default Configuration documentation. Items with (CSV) after the name only apply to the CSV format; items with (XML) only apply to XML format. CSV format cannot currently be used to save any items that include line-breaks.
Note that cookies, method and the query string are saved as part of the "Sampler Data" option.
The Graph Results listener generates a simple graph that plots all sample times. Along the bottom of the graph, the current sample (black), the current average of all samples(blue), the current standard deviation (red), and the current throughput rate (green) are displayed in milliseconds.
The throughput number represents the actual number of requests/minute the server handled. This calculation includes any delays you added to your test and JMeter's own internal processing time. The advantage of doing the calculation like this is that this number represents something real - your server in fact handled that many requests per minute, and you can increase the number of threads and/or decrease the delays to discover your server's maximum throughput. Whereas if you made calculations that factored out delays and JMeter's processing, it would be unclear what you could conclude from that number.
The following table briefly describes the items on the graph. Further details on the precise meaning of the statistical terms can be found on the web - e.g. Wikipedia - or by consulting a book on statistics.
The individual figures at the bottom of the display are the current values. "Latest Sample" is the current elapsed sample time, shown on the graph as "Data".
The Spline Visualizer provides a view of all sample times from the start of the test till the end, regardless of how many samples have been taken. The spline has 10 points, each representing 10% of the samples, and connected using spline logic to show a single continuous line.
The graph is automatically scaled to fit within the window. This needs to be borne in mind when comparing graphs.
The Assertion Results visualizer shows the Label of each sample taken. It also reports failures of any Assertions that are part of the test plan.
There are several ways to view the response, selectable by a radio button.
The default "Show text" view shows all of the text contained in the response. Note that this will only work if the response content-type is considered to be text. If the content-type begins with any of the following, it is considered as binary, otherwise it is considered to be text.
image/ audio/ video/If there is no content-type provided, then the content will not be displayed in the any of the Response Data panels. You can use
If the response data is larger than 200K, then it won't be displayed.
To change this limit, set the JMeter property view.results.tree.max_size.
You can also use save the entire response to a file using
The HTML view attempts to render the response as HTML. The rendered HTML is likely to compare poorly to the view one would get in any web browser; however, it does provide a quick approximation that is helpful for initial result evaluation. If the "Download embedded resources" check-box is selected, the renderer may download images and style-sheets etc referenced by the HTML. If the checkbox is not selected, the renderer will not download images etc.
The Render XML view will show response in tree style. Any DTD nodes or Prolog nodes will not show up in tree; however, response may contain those nodes.
The Render JSON view will show the response in tree style (also handles JSON embedded in JavaScript).
The Control Panel (above) shows an example of an HTML display.
Figure 9 (below) shows an example of an XML display.
The thoughput is calculated from the point of view of the sampler target (e.g. the remote server in the case of HTTP samples). JMeter takes into account the total time over which the requests have been generated. If other samplers and timers are in the same thread, these will increase the total time, and therefore reduce the throughput value. So two identical samplers with different names will have half the throughput of two samplers with the same name. It is important to choose the sampler names correctly to get the best results from the Aggregate Report.
Times are in milliseconds.
The figure below shows an example of selecting the "Include group name" checkbox.
Monitor Results is a new Visualizer for displaying server status. It is designed for Tomcat 5, but any servlet container can port the status servlet and use this monitor. There are two primary tabs for the monitor. The first is the "Health" tab, which will show the status of one or more servers. The second tab labled "Performance" shows the performance for one server for the last 1000 samples. The equations used for the load calculation is included in the Visualizer.
Currently, the primary limitation of the monitor is system memory. A quick benchmark of memory usage indicates a buffer of 1000 data points for 100 servers would take roughly 10Mb of RAM. On a 1.4Ghz centrino laptop with 1Gb of ram, the monitor should be able to handle several hundred servers.
As a general rule, monitoring production systems should take care to set an appropriate interval. Intervals shorter than 5 seconds are too aggressive and have a potential of impacting the server. With a buffer of 1000 data points at 5 second intervals, the monitor would check the server status 12 times a minute or 720 times a hour. This means the buffer shows the performance history of each machine for the last hour.
For a detailed description of how to use the monitor, please refer to Building a Monitor Test Plan
The distribution graph will display a bar for every unique response time. Since the granularity of System.currentTimeMillis() is 10 milliseconds, the 90% threshold should be within the width of the graph. The graph will draw two threshold lines: 50% and 90%. What this means is 50% of the response times finished between 0 and the line. The same is true of 90% line. Several tests with Tomcat were performed using 30 threads for 600K requests. The graph was able to display the distribution without any problems and both the 50% and 90% line were within the width of the graph. A performant application will generally produce results that clump together. A poorly written application that has memory leaks may result in wild fluctuations. In those situations, the threshold lines may be beyond the width of the graph. The recommended solution to this specific problem is fix the webapp so it performs well. If your test plan produces distribution graphs with no apparent clumping or pattern, it may indicate a memory leak. The only way to know for sure is to use a profiling tool.
The mailer visualizer can be set up to send email if a test run receives too many failed responses from the server.
The BeanShell Listener allows the use of BeanShell for processing samples for saving etc.
For full details on using BeanShell, please see the BeanShell web-site at http://www.beanshell.org/.
The test element supports the ThreadListener and TestListener methods. These should be defined in the initialisation file. See the file BeanShellListeners.bshrc for example definitions.
Before invoking the script, some variables are set up in the BeanShell interpreter:
For details of all the methods available on each of the above variables, please check the Javadoc
If the property beanshell.listener.init is defined, this is used to load an initialisation file, which can be used to define methods etc for use in the BeanShell script.
The thoughput is calculated from the point of view of the sampler target (e.g. the remote server in the case of HTTP samples). JMeter takes into account the total time over which the requests have been generated. If other samplers and timers are in the same thread, these will increase the total time, and therefore reduce the throughput value. So two identical samplers with different names will have half the throughput of two samplers with the same name. It is important to choose the sampler labels correctly to get the best results from the Report.
Times are in milliseconds.
The figure below shows an example of selecting the "Include group name" checkbox.
This test element can be placed anywhere in the test plan.
For each sample in its scope, it will create a file of the response Data.
The primary use for this is in creating functional tests, but it can also
be useful where the response is too large to be displayed in the
The current sample is saved first, followed by any sub-samples (child samples). If a variable name is provided, then the names of the files are saved in the order that the sub-samples appear. See below.
The BSF Listener allows BSF script code to be applied to sample results.
The script (or file) is processed using the BSFEngine.exec() method, which does not return a value.
Before invoking the script, some variables are set up. Note that these are BSF variables - i.e. they can be used directly in the script.
For details of all the methods available on each of the above variables, please check the Javadoc
label + 171 in 20.3s = 8.4/s Avg: 1129 Min: 1000 Max: 1250 Err: 0 (0.00%) label + 263 in 31.3s = 8.4/s Avg: 1138 Min: 1000 Max: 1250 Err: 0 (0.00%) label = 434 in 50.4s = 8.6/s Avg: 1135 Min: 1000 Max: 1250 Err: 0 (0.00%) label + 263 in 31.0s = 8.5/s Avg: 1138 Min: 1000 Max: 1250 Err: 0 (0.00%) label = 697 in 80.3s = 8.7/s Avg: 1136 Min: 1000 Max: 1250 Err: 0 (0.00%) label + 109 in 12.4s = 8.8/s Avg: 1092 Min: 47 Max: 1250 Err: 0 (0.00%) label = 806 in 91.6s = 8.8/s Avg: 1130 Min: 47 Max: 1250 Err: 0 (0.00%)The "label" is the the name of the element. The "+" means that the line is a delta line, i.e. shows the changes since the last output. The "=" means that the line is a totals line, i.e. it shows the running total. Entries in the jmeter log file also include time-stamps. The example "806 in 91.6s = 8.8/s" means that there were 806 samples recorded in 91.6 seconds, and that works out at 8.8 samples per second. The Avg (Average), Min(imum) and Max(imum) times are in milliseconds. "Err" means number of errors (also shown as percentage). The last two lines will appear at the end of a test. They will not be synchronised to the appropriate time boundary. Note that the initial and final deltas may be for less than the interval (in the example above this is 30 seconds). The first delta will generally be lower, as JMeter synchronises to the interval boundary. The last delta will be lower, as the test will generally not finish on an exact interval boundary.
The label is used to group sample results together. So if you have multiple Thread Groups and want to summarize across them all, then use the same label - or add the summariser to the Test Plan (so all thread groups are in scope). Different summary groupings can be implemented by using suitable labels and adding the summarisers to appropriate parts of the test plan.
CSV Data Set Config is used to read lines from a file, and split them into variables. It is easier to use than the __CSVRead() and _StringFromFile() functions. It is well suited to handling large numbers of variables, and is also useful for tesing with "random" and unique values. Generating unique random values at run-time is expensive in terms of CPU and memory, so just create the data in advance of the test. If necessary, the "random" data from the file can be used in conjunction with a run-time parameter to create different sets of values from each run - e.g. using concatenation - which is much cheaper than generating everything at run-time.
Versions of JMeter after 2.3.1 allow variables to be quoted; this allows the value to contain a delimiter. Previously it was necessary to choose a delimiter that was not used in any values.
By default, the file is only opened once, and each thread will use a different line from the file. However the order in which lines are passed to threads depends on the order in which they execute, which may vary between iterations. Lines are read at the start of each test iteration. The file name and mode are resolved in the first iteration.
See the description of the Share mode below for additional options (JMeter 2.3.2+).
If you want each thread to have its own set of values, then you will need to create a set of files,
one for each thread. For example test1.csv, test2.csv,... testn.csv. Use the filename
test${__threadNum}.csv and set the "Sharing mode" to "Current thread".
As a special case, the string "\t" (without quotes) in the delimiter field is treated as a Tab.
When the end of file (EOF) is reached, and the recycle option is true, reading starts again with the first line of the file.
If the recycle option is false, and stopThread is false, then all the variables are set to <EOF> when the end of file is reached. This value can be changed by setting the JMeter property csvdataset.eofstring.
If the Recycle option is false, and Stop Thread is true, then reaching EOF will cause the thread to be stopped.
The Authorization Manager lets you specify one or more user logins for web pages that are restricted using server authentication. You see this type of authentication when you use your browser to access a restricted page, and your browser displays a login dialog box. JMeter transmits the login information when it encounters this type of page.
The Authorisation headers are not shown in the Tree View Listener.
In versions of JMeter after 2.2, the HttpClient sampler defaults to pre-emptive authentication if the setting has not been defined. To disable this, set the values as below, in which case authentication will only be performed in response to a challenge.
jmeter.properties: httpclient.parameters.file=httpclient.parameters httpclient.parameters: http.authentication.preemptive$Boolean=falseNote: the above settings only apply to the HttpClient sampler (and the SOAP samplers, which use Httpclient).
Download this example. In this example, we created a Test Plan on a local server that sends three HTTP requests, two requiring a login and the other is open to everyone. See figure 10 to see the makeup of our Test Plan. On our server, we have a restricted directory named, "secret", which contains two files, "index.html" and "index2.html". We created a login id named, "kevin", which has a password of "spot". So, in our Authorization Manager, we created an entry for the restricted directory and a username and password (see figure 11). The two HTTP requests named "SecretPage1" and "SecretPage2" make requests to "/secret/index.html" and "/secret/index2.html". The other HTTP request, named "NoSecretPage" makes a request to "/index.html".
When we run the Test Plan, JMeter looks in the Authorization table for the URL it is requesting. If the Base URL matches the URL, then JMeter passes this information along with the request.
The HTTP Cache Manager is used to add caching functionality to HTTP requests within its scope.
If a sample is successful (i.e. has response code 2xx) then the Last-Modified and Etag values are saved for the URL. Before executing the next sample, the sampler checks to see if there is an entry in the cache, and if so, the If-Last-Modified and If-None-Match conditional headers are set for the request.
If the requested document has not changed since it was cached, then the response body will be empty. This may cause problems for Assertions.
The Cookie Manager element has two functions:
First, it stores and sends cookies just like a web browser. If you have an HTTP Request and
the response contains a cookie, the Cookie Manager automatically stores that cookie and will
use it for all future requests to that particular web site. Each JMeter thread has its own
"cookie storage area". So, if you are testing a web site that uses a cookie for storing
session information, each JMeter thread will have its own session.
Note that such cookies do not appear on the Cookie Manager display, but they can be seen using
the
JMeter version 2.3.2 and earlier did not check that received cookies were valid for the URL. This meant that cross-domain cookies were stored, and might be used later. This has been fixed in later versions. To revert to the earlier behaviour, define the JMeter property "CookieManager.check.cookies=false".
Received Cookies can be stored as JMeter thread variables (versions of JMeter after 2.3.2 no longer do this by default). To save cookies as variables, define the property "CookieManager.save.cookies=true". Also, cookies names are prefixed with "COOKIE_" before they are stored (this avoids accidental corruption of local variables) To revert to the original behaviour, define the property "CookieManager.name.prefix= " (one or more spaces). If enabled, the value of a cookie with the name TEST can be referred to as ${COOKIE_TEST}.
Second, you can manually add a cookie to the Cookie Manager. However, if you do this, the cookie will be shared by all JMeter threads.
Note that such Cookies are created with an Expiration time far in the future
Since version 2.0.3, cookies with null values are ignored by default. This can be changed by setting the JMeter property: CookieManager.delete_null_cookies=false. Note that this also applies to manually defined cookies - any such cookies will be removed from the display when it is updated. Note also that the cookie name must be unique - if a second cookie is defined with the same name, it will replace the first.
This element lets you set default values that your HTTP Request controllers use. For example, if you are creating a Test Plan with 25 HTTP Request controllers and all of the requests are being sent to the same server, you could add a single HTTP Request Defaults element with the "Server Name or IP" field filled in. Then, when you add the 25 HTTP Request controllers, leave the "Server Name or IP" field empty. The controllers will inherit this field value from the HTTP Request Defaults element.
The Header Manager lets you add or override HTTP request headers.
Versions of JMeter up to 2.3.2 supported only one Header Manager per sampler; if there were more in scope, then only the last one would be used.
JMeter now supports multiple Header Managers. The header entries are merged to form the list for the sampler. If an entry to be merged matches an existing header name, it replaces the previous entry, unless the entry value is empty, in which case any existing entry is removed. This allows one to set up a default set of headers, and apply adjustments to particular samplers.
Download this example. In this example, we created a Test Plan that tells JMeter to override the default "User-Agent" request header and use a particular Internet Explorer agent string instead. (see figures 9 and 10).
The Java Request Defaults component lets you set default values for Java testing. See the
Different databases and JDBC drivers require different JDBC settings. The Database URL and JDBC Driver class are defined by the provider of the JDBC implementation.
Some possible settings are shown below. Please check the exact details in the JDBC driver documentation.
If JMeter reports No suitable driver, then this could mean either:
| Database | Driver class | Database URL |
|---|---|---|
| MySQL | com.mysql.jdbc.Driver | jdbc:mysql://host[:port]/dbname |
| PostgreSQL | org.postgresql.Driver | jdbc:postgresql:{dbname} |
| Oracle | oracle.jdbc.driver.OracleDriver | jdbc:oracle:thin:@//host:port/service
OR jdbc:oracle:thin:@(description=(address=(host={mc-name})(protocol=tcp)(port={port-no}))(connect_data=(sid={sid}))) |
| Ingres (2006) | ingres.jdbc.IngresDriver | jdbc:ingres://host:port/db[;attr=value] |
| SQL Server (MS JDBC driver) | com.microsoft.sqlserver.jdbc.SQLServerDriver | jdbc:sqlserver://host:port;DatabaseName=dbname |
| Apache Derby | org.apache.derby.jdbc.ClientDriver | jdbc:derby://server[:port]/databaseName[;URLAttributes=value[;...]] |
The Login Config Element lets you add or override username and password settings in samplers that use username and password as part of their setup.
The LDAP Request Defaults component lets you set default values for LDAP testing. See the
The LDAP Extended Request Defaults component lets you set default values for extended LDAP testing. See the
The TCP Sampler Config provides default data for the TCP Sampler
The User Defined Variables element lets you define an initial set of variables, just as in the
UDVs should not be used with functions that generate different results each time they are called. Only the result of the first function call will be saved in the variable. However, UDVs can be used with functions such as __P(), for example:
HOST ${__P(host,localhost)}
which would define the variable "HOST" to have the value of the JMeter property "host", defaulting to "localhost" if not defined.
For defining variables during a test run, see
For simplicity, it is suggested that UDVs are placed only at the start of a Thread Group (or perhaps under the Test Plan itself).
Once the Test Plan and all UDVs have been processed, the resulting set of variables is copied to each thread to provide the initial set of variables.
If a runtime element such as a User Parameters Pre-Processor or Regular Expression Extractor defines a variable with the same name as one of the UDV variables, then this will replace the initial value, and all other test elements in the thread will see the updated value.
The Random Variable Config Element is used to generate random numeric strings and store them in variable for use later.
It's simpler than using
The output variable is constructed by using the random number generator,
and then the resulting number is formatted using the format string.
The number is calculated using the formula minimum+Random.nextInt(maximum-minimum+1).
Random.nextInt() requires a positive integer.
This means that maximum-minimum - i.e. the range - must be less than 2147483647,
however the minimum and maximum values can be any long values so long as the range is OK.
Allows the user to create a counter that can be referenced anywhere in the Thread Group. The counter config lets the user configure a starting point, a maximum, and the increment. The counter will loop from the start to the max, and then start over with the start, continuing on like that until the test is ended.
From version 2.1.2, the counter now uses a long to store the value, so the range is from -2^63 to 2^63-1.
$(reference_name}.The Simple Config Element lets you add or override arbitrary values in samplers. You can choose the name of the value and the value itself. Although some adventurous users might find a use for this element, it's here primarily for developers as a basic GUI that they can use while developing new JMeter components.
Assertions are used to perform additional checks on samplers, and are processed after every sampler in the same scope. To ensure that an Assertion is applied only to a particular sampler, add it as a child of the sampler.
Note: Unless documented otherwise, Assertions are not applied to sub-samples (child samples) -
only to the parent sample.
In the case of BSF and BeanShell Assertions, the script can retrieve sub-samples using the method
prev.getSubResults() which returns an array of SampleResults.
The array will be empty if there are none.
Versions of JMeter after 2.3.2 include the option to apply certain assertions
to either the main sample, the sub-samples or both.
The default is to apply the assertion to the main sample only.
If the Assertion supports this option, then there will be an entry on the GUI which looks like the following:
The response assertion control panel lets you add pattern strings to be compared against various fields of the response. The pattern strings are:
A summary of the pattern matching characters can be found at http://jakarta.apache.org/oro/api/org/apache/oro/text/regex/package-summary.html
You can also choose whether the strings will be expected to match the entire response, or if the response is only expected to contain the pattern. You can attach multiple assertions to any controller for additional flexibility.
Note that the pattern string should not include the enclosing delimiters, i.e. use Price: \d+ not /Price: \d+/.
By default, the pattern is in multi-line mode, which means that the "." meta-character does not match newline. In multi-line mode, "^" and "$" match the start or end of any line anywhere within the string - not just the start and end of the entire string. Note that \s does match new-line. Case is also significant. To override these settings, one can use the extended regular expression syntax. For example:
(?i) - ignore case
(?s) - treat target as single line, i.e. "." matches new-line
(?is) - both the above
These can be used anywhere within the expression and remain in effect until overriden. e.g.
(?i)apple(?-i) Pie - matches "ApPLe Pie", but not "ApPLe pIe"
(?s)Apple.+?Pie - matches Apple followed by Pie, which may be on a subsequent line.
Apple(?s).+?Pie - same as above, but it's probably clearer to use the (?s) at the start.
The overall success of the sample is determined by combining the result of the assertion with the existing Response status. When the Ignore Status checkbox is selected, the Response status is forced to successful before evaluating the Assertion.
HTTP Responses with statuses in the 4xx and 5xx ranges are normally regarded as unsuccessful. The "Ignore status" checkbox can be used to set the status successful before performing further checks. Note that this will have the effect of clearing any previous assertion failures, so make sure that this is only set on the first assertion.The pattern is a Perl5-style regular expression, but without the enclosing brackets.
The Duration Assertion tests that each response was received within a given amount of time. Any response that takes longer than the given number of milliseconds (specified by the user) is marked as a failed response.
The Size Assertion tests that each response contains the right number of bytes in it. You can specify that the size be equal to, greater than, less than, or not equal to a given number of bytes.
The XML Assertion tests that the response data consists of a formally correct XML document. It does not validate the XML based on a DTD or schema or do any further validation.
The BeanShell Assertion allows the user to perform assertion checking using a BeanShell script.
For full details on using BeanShell, please see the BeanShell web-site at http://www.beanshell.org/.
Note that a different Interpreter is used for each independent occurence of the assertion in each thread in a test script, but the same Interpreter is used for subsequent invocations. This means that variables persist across calls to the assertion.
All Assertions are called from the same thread as the sampler.
If the property "beanshell.assertion.init" is defined, it is passed to the Interpreter as the name of a sourced file. This can be used to define common methods and variables. There is a sample init file in the bin directory: BeanShellAssertion.bshrc
The test element supports the ThreadListener and TestListener methods. These should be defined in the initialisation file. See the file BeanShellListeners.bshrc for example definitions.
There's a sample script you can try.
Before invoking the script, some variables are set up in the BeanShell interpreter. These are strings unless otherwise noted:
The following methods of the Response object may be useful:
The MD5Hex Assertion allows the user to check the MD5 hash of the response data.
The HTML Assertion allows the user to check the HTML syntax of the response data using JTidy.
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". See http://www.w3.org/TR/xpath for more information on XPath.
The XML Schema Assertion allows the user to validate a response against an XML Schema.
The BSF Assertion allows BSF script code to be used to check the status of the previous sample.
The script (or file) is processed using the BSFEngine.exec() method, which does not return a value.
The following variables are set up for use by the script:
The script can check various aspects of the SampleResult. If an error is detected, the script should use AssertionResult.setFailureMessage("message") and AssertionResult.setFailure(true).
For futher details of all the methods available on each of the above variables, please check the Javadoc
Note that timers are processed before each sampler in the scope in which they are found;
if there are several timers in the same scope, all the timers will be processed before
each sampler.
Timers are only processed in conjunction with a sampler.
A timer which is not in the same scope as a sampler will not be processed at all.
To apply a timer to a single sampler, add the timer as a child element of the sampler.
The timer will be applied before the sampler is executed.
To apply a timer after a sampler, either add it to the next sampler, or add it as the
child of a
If you want to have each thread pause for the same amount of time between requests, use this timer.
This timer pauses each thread request for a random amount of time, with most of the time intervals ocurring near a particular value. The total delay is the sum of the Gaussian distributed value (with mean 0.0 and standard deviation 1.0) times the deviation value you specify, and the offset value.
This timer pauses each thread request for a random amount of time, with each time interval having the same probability of occurring. The total delay is the sum of the random value and the offset value.
This timer introduces variable pauses, calculated to keep the total throughput (in terms of samples per minute) as close as possible to a give figure. Of course the throughput will be lower if the server is not capable of handling it, or if other timers or time-consuming test elements prevent it.
N.B. although the Timer is called the Constant Throughput timer, the throughput value does not need to be constant. It can be defined in terms of a variable or function call, and the value can be changed during a test. The value can be changed in various ways:
See Best Practices for further details. Note that the throughput value should not be changed too often during a test - it will take a while for the new value to take effect.
The shared and non-shared algorithms both aim to generate the desired thoughput, and will produce similar results. The shared algorithm should generate a more accurate overall transaction rate. The non-shared algortihm should generate a more even spread of transactions across threads.
The purpose of the SyncTimer is to block threads until X number of threads have been blocked, and then they are all released at once. A SyncTimer can thus create large instant loads at various points of the test plan.
The BeanShell Timer can be used to generate a delay.
For full details on using BeanShell, please see the BeanShell web-site at http://www.beanshell.org/.
The test element supports the ThreadListener and TestListener methods. These should be defined in the initialisation file. See the file BeanShellListeners.bshrc for example definitions.
Before invoking the script, some variables are set up in the BeanShell interpreter:
For details of all the methods available on each of the above variables, please check the Javadoc
If the property beanshell.timer.init is defined, this is used to load an initialisation file, which can be used to define methods etc for use in the BeanShell script.
This modifier parses HTML response from the server and extracts links and forms. A URL test sample that passes through this modifier will be examined to see if it "matches" any of the links or forms extracted from the immediately previous response. It would then replace the values in the URL test sample with appropriate values from the matching link or form. Perl-type regular expressions are used to find matches.
Consider a simple example: let's say you wanted JMeter to "spider" through your site,
hitting link after link parsed from the HTML returned from your server (this is not
actually the most useful thing to do, but it serves as a good example). You would create
a
A more useful example: given a web polling application, you might have a page with several poll options as radio buttons for the user to select. Let's say the values of the poll options are very dynamic - maybe user generated. If you wanted JMeter to test the poll, you could either create test samples with hardcoded values chosen, or you could let the HTML Link Parser parse the form, and insert a random poll option into your URL test sample. To do this, follow the above example, except, when configuring your Web Test controller's URL options, be sure to choose "POST" as the method. Put in hard-coded values for the domain, path, and any additional form parameters. Then, for the actual radio button parameter, put in the name (let's say it's called "poll_choice"), and then ".*" for the value of that parameter. When the modifier examines this URL test sample, it will find that it "matches" the poll form (and it shouldn't match any other form, given that you've specified all the other aspects of the URL test sample), and it will replace your form parameters with the matching parameters from the form. Since the regular expression ".*" will match with anything, the modifier will probably have a list of radio buttons to choose from. It will choose at random, and replace the value in your URL test sample. Each time through the test, a new random value will be chosen.
This modifier works similarly to the HTML Link Parser, except it has a specific purpose for which
it is easier to use than the HTML Link Parser, and more efficient. 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
Alternatively, this modifier can be attached to select requests and it will modify only them.
Clever users will even determine that this modifier can be used to grab values that elude the
The HTML Parameter Mask is used to generate unique values for HTML arguments. By
specifying the name of the parameter, a value prefix and suffix, and counter parameters, this
modifier will generate values of the form "name=prefixcountersuffix". Any HTTP
Request that it modifies, it will replace any parameter with the same name or add the appropriate
parameter to the requests list of arguments.
As an example, the username for a login script could be modified to send a series of values
such as:
user_1
user_2
user_3
user_4, etc.
See also the
The User Parameter Modifier uses an XML file get values for HTTP arguments. Any HTTP Request that this modifier modifies will be checked for the existence of the specified arguments. If found, the values for those arguments will be replaced by the values found in the xml file. The XML file can have multiple sets of the same values. This modifier will iterate through these values in a round-robin style, thus each request will get a different set of values until the last set of values is reached, at which point it will begin again at the first set.
Allows the user to specify values for User Variables specific to individual threads.
User Variables can also be specified in the Test Plan but not specific to individual threads. This panel allows you to specify a series of values for any User Variable. For each thread, the variable will be assigned one of the values from the series in sequence. If there are more threads than values, the values get re-used. For example, this can be used to assign a distinct user id to be used by each thread. User variables can be referenced in any field of any jMeter Component.
The variable is specified by clicking the Add Variable button in the bottom of the panel and filling in the Variable name in the 'Name:' column. To add a new value to the series, click the 'Add User' button and fill in the desired value in the newly added column.
Values can be accessed in any test component in the same thread group, using the function syntax: ${variable}.
See also the
The BeanShell PreProcessor allows arbitrary code to be applied before taking a sample.
For full details on using BeanShell, please see the BeanShell web-site at http://www.beanshell.org/.
The test element supports the ThreadListener and TestListener methods. These should be defined in the initialisation file. See the file BeanShellListeners.bshrc for example definitions.
Before invoking the script, some variables are set up in the BeanShell interpreter:
For details of all the methods available on each of the above variables, please check the Javadoc
If the property beanshell.preprocessor.init is defined, this is used to load an initialisation file, which can be used to define methods etc for use in the BeanShell script.
The BSF PreProcessor allows BSF script code to be applied before taking a sample.
The script (or file) is processed using the BSFEngine.exec() method, which does not return a value.
The following BSF variables are set up for use by the script:
For details of all the methods available on each of the above variables, please check the Javadoc
As the name suggests, Post-Processors are applied after samplers. Note that they are applied to all the samplers in the same scope, so to ensure that a post-processor is applied only to a particular sampler, add it as a child of the sampler.
Note: Unless documented otherwise, Post-Processors are not applied to sub-samples (child samples) -
only to the parent sample.
In the case of BSF and BeanShell post-processors, the script can retrieve sub-samples using the method
prev.getSubResults() which returns an array of SampleResults.
The array will be empty if there are none.
Post-Processors are run before Assertions, so they do not have access to any Assertion Results, nor will the sample status reflect the results of any Assertions. If you require access to Assertion Results, try using a Listener instead. Also note that the variable JMeterThread.last_sample_ok is set to "true" or "false" after all Assertions have been run.
Allows the user to extract values from a server response using a Perl-type regular expression. As a post-processor, this element will execute after each Sample request in its scope, applying the regular expression, extracting the requested values, generate the template string, and store the result into the given variable name.
However, if you have several test elements that set the same variable, you may wish to leave the variable unchanged if the expression does not match. In this case, remove the default value once debugging is complete.
If the match number is set to a non-negative number, and a match occurs, the variables are set as follows:
If the match number is set to a negative number, then all the possible matches in the sampler data are processed. The variables are set as follows:
See also
To allow for use in a ForEach Controller, the following variables are set on return:
Note: The next refName_n variable is set to null - e.g. if there are 2 matches, then refName_3 is set to null, and if there are no matches, then refName_1 is set to null.
XPath is query language targeted primarily for XSLT transformations. However it is usefull as generic query language for structured data too. See XPath Reference or XPath specification for more information. Here are few examples:
ul/font/li becomes correct ul/li/fontThe BeanShell PreProcessor allows arbitrary code to be applied after taking a sample.
For JMeter versions after 2.2 the BeanShell Post-Processor no longer ignores samples with zero-length result data
For full details on using BeanShell, please see the BeanShell web-site at http://www.beanshell.org/.
The test element supports the ThreadListener and TestListener methods. These should be defined in the initialisation file. See the file BeanShellListeners.bshrc for example definitions.
The following BeanShell variables are set up for use by the script:
For details of all the methods available on each of the above variables, please check the Javadoc
If the property beanshell.postprocessor.init is defined, this is used to load an initialisation file, which can be used to define methods etc for use in the BeanShell script.
The BSF PostProcessor allows BSF script code to be applied after taking a sample.
The script (or file) is processed using the BSFEngine.exec() method, which does not return a value.
Before invoking the script, some variables are set up. Note that these are BSF variables - i.e. they can be used directly in the script.
For details of all the methods available on each of the above variables, please check the Javadoc
The Test Plan is where the overall settings for a test are specified.
Static variables can be defined for values that are repeated throughout a test, such as server names. For example the variable SERVER could be defined as www.example.com, and the rest of the test plan could refer to it as ${SERVER}. This simplifies changing the name later.
If the same variable name is reused on one of more
Note that the Test Plan cannot refer to variables it defines.
If you need to construct other variables from the Test Plan variables,
use a
Selecting Functional Testing instructs JMeter to save the additional sample information - Response Data and Sampler Data - to all result files. This increases the resources needed to run a test, and may adversely impact JMeter performance. If more data is required for a particular sampler only, then add a Listener to it, and configure the fields as required. [The option does not affect CSV result files, which cannot currently store such information.]
Also, an option exists here to instruct JMeter to run the
Test plan now provides an easy way to add classpath setting to a specific test plan. The feature is additive, meaning that you can add jar files or directories, but removing an entry requires restarting JMeter. In the past, users had to copy all the jar files to jmeter/lib/ directory. Now that is not necessary. JMeter properties also provides an entry for loading additional classpaths.
In jmeter.properties, edit "user.classpath" to include additional libraries.
A Thread Group defines a pool of users that will execute a particular test case against your server. In the Thread Group GUI, you can control the number of users simulated (num of threads), the ramp up time (how long it takes to start all the threads), the number of times to perform the test, and optionally, a start and stop time for the test.
When using the scheduler, JMeter runs the thread group until either the number of loops is reached or the duration/end-time is reached - whichever occurs first. Note that the condition is only checked between samples; when the end condition is reached, that thread will stop. JMeter does not interrupt samplers which are waiting for a response, so the end time may be delayed arbitrarily.
The WorkBench simply provides a place to temporarily store test elements while not in use, for copy/paste purposes, or any other purpose you desire. When you save your test plan, WorkBench items are not saved with it. Your WorkBench can be saved independently, if you like (right-click on WorkBench and choose Save).
Certain test elements are only available on the WorkBench:
The SSL Manager is a way to select a client certificate so that you can test applications that use Public Key Infrastructure (PKI). It is only needed if you have not set up the appropriate System properties.
Choosing a Client CertificateYou may either use a Java Key Store (JKS) format key store, or a Public Key Certificate Standard #12 (PKCS12) file for your client certificates. There is a feature of the JSSE libraries that require you to have at least a six character password on your key (at least for the keytool utility that comes with your JDK).
To select the client certificate, choose Options->SSL Manager from the menu bar. You will be presented with a file finder that looks for PKCS12 files by default. Your PKCS12 file must have the extension '.p12' for SSL Manager to recognize it as a PKCS12 file. Any other file will be treated like an average JKS key store. If JSSE is correctly installed, you will be prompted for the password. The text box does not hide the characters you type at this point--so make sure no one is looking over your shoulder. The current implementation assumes that the password for the keystore is also the password for the private key of the client you want to authenticate as.
Or you can set the appropriate System properties - see the system.properties file.
The next time you run your test, the SSL Manager will examine your key store to see if it has at least one key available to it. If there is only one key, SSL Manager will select it for you. If there is more than one key, it currently selects the first key. There is currently no way to select other entries in the keystore, so the desired key must be the first.
Things to Look Out ForYou must have your Certificate Authority (CA) certificate installed properly if it is not signed by one of the five CA certificates that ships with your JDK. One method to install it is to import your CA certificate into a JKS file, and name the JKS file "jssecacerts". Place the file in your JRE's lib/security folder. This file will be read before the "cacerts" file in the same directory. Keep in mind that as long as the "jssecacerts" file exists, the certificates installed in "cacerts" will not be used. This may cause problems for you. If you don't mind importing your CA certificate into the "cacerts" file, then you can authenticate against all of the CA certificates installed.
The Proxy Server allows JMeter to watch and record your actions while you browse your web application with your normal browser. JMeter will create test sample objects and store them directly into your test plan as you go (so you can view samples interactively while you make them).
To use the proxy server, add the HTTP Proxy Server element to the workbench. Select the WorkBench element in the tree, and right-click on this element to get the Add menu (Add --> Non-Test Elements --> HTTP Proxy Server).
You also need to set up your browser to use the JMeter proxy port as the proxy for HTTP and HTTPS requests. Do not use JMeter as the proxy for any other request types - FTP, etc. - as the JMeter proxy cannot handle them.
When recording HTTPS, the JMeter proxy server uses a dummy certificate to enable it to accept the SSL connection from
the browser. This certificate is not one of the certificates that browsers normally trust, and will not be for the
correct host, so the browser should display a dialogue asking if you want to accept the certificate or not. For example:
1) The server's name "www.example.com" does not match the certificate's name
"JMeter Proxy". Somebody may be trying to eavesdrop on you.
2) The certificate for "JMeter Proxy" is signed by the unknown Certificate Authority
"JMeter Proxy". It is not possible to verify that this is a valid certificate.
You will need to accept the certificate in order to allow the JMeter Proxy to intercept the SSL traffic in order to
record it. You should only accept the certificate temporarily.
The include and exclude patterns are treated as regular expressions (using Jakarta ORO).
They will be matched against the host name, port (actual or implied) path and query (if any) of each browser request.
If the URL you are browsing is
"http://jakarta.apache.org/jmeter/index.html?username=xxxx",
then the regular expression will be tested against the string:
"jakarta.apache.org:80/jmeter/index.html?username=xxxx".
Thus, if you want to include all .html files, your regular expression might look like:
".*\.html(\?.*)?" - or ".*\.html"
if you know that there is no query string or you only want html pages without query strings.
If there are any include patterns, then the URL must match at least one of the patterns , otherwise it will not be recorded. If there are any exclude patterns, then the URL must not match any of the patterns , otherwise it will not be recorded. Using a combination of includes and excludes, you should be able to record what you are interested in and skip what you are not.
N.B. the string that is matched by the regular expression must be the same as the whole host+path string.
Thus "\.html" will not match j.a.o/index.html
Versions of JMeter from 2.3.2 are able to capture binary POST data. To configure which content-types are treated as binary, update the JMeter property proxy.binary.types. The default settings are as follows:
# These content-types will be handled by saving the request in a file: proxy.binary.types=application/x-amf,application/x-java-serialized-object # The files will be saved in this directory: proxy.binary.directory=user.dir # The files will be created with this file filesuffix: proxy.binary.filesuffix=.binary
It is also possible to have the proxy add timers to the recorded script. To do this, create a timer directly within the HTTP Proxy Server component. The proxy will place a copy of this timer into each sample it records, or into the first sample of each group if you're using grouping. This copy will then be scanned for occurences of variable ${T} in its properties, and any such occurences will be replaced by the time gap from the previous sampler recorded (in milliseconds).
When you are ready to begin, hit "start".
Where Do Samples Get Recorded?
JMeter places the recorded samples in the Target Controller you choose. If you choose the default option "Use Recording Controller", they will be stored in the first Recording Controller found in the test object tree (so be sure to add a Recording Controller before you start recording).
If the Proxy does not seem to record any samples, this could be because the browser is not actually using the proxy. To check if this is the case, try stopping the proxy. If the browser still downloads pages, then it was not sending requests via the proxy. Double-check the browser options. If you are trying to record from a server running on the same host, then check that the browser is not set to "Bypass proxy server for local addresses" (this example is from IE7, but there will be similar options for other browsers). If JMeter does not record browser URLs such as http://localhost/ or http://127.0.0.1/, try using the non-loopback hostname or IP address, e.g. http://myhost/ or http://192.168.0.2/.
Handling of HTTP Request Defaults
If the HTTP Proxy Server finds enabled
User Defined Variable replacement
Similarly, if the HTTP Proxy Server finds
Replacement by Variables: by default, the Proxy server looks for all occurences of UDV values.
If you define the variable "WEB" with the value "www", for example,
the string "www" will be replaced by ${WEB} wherever it is found.
To avoid this happening everywhere, set the "Regex Matching" check-box.
This tells the proxy server to treat values as Regexes (using ORO).
If you want to match a whole string only, enclose it in ^$, e.g. "^thus$".
If you want to match /images at the start of a string only, use the value "^/images".
Jakarta ORO also supports zero-width look-ahead, so one can match /images/...
but retain the trailing / in the output by using "^/images(?=/)".
Note that the current version of Jakara ORO does not support look-behind - i.e. "(?<=...) or (?<!...)".
If there are any problems interpreting any variables as patterns, these are reported in jmeter.log,
so be sure to check this if UDVs are not working as expected.
When you are done recording your test samples, stop the proxy server (hit the "stop" button). Remember to reset your browser's proxy settings. Now, you may want to sort and re-order the test script, add timers, listeners, a cookie manager, etc.
How can I record the server's responses too?
Just place a
Cookie Manager
If the server you are testing against uses cookies, remember to add an
Authorization Manager
The Proxy server passes on any Authorization headers sent by the browser, but does not save them in the test plan. If the site requires Authorization, you will need to add an Authorization Manager and fill it in with the necessary entries.
Uploading files
Some browsers (e.g. Firefox and Opera) don't include the full name of a file when uploading files. This can cause the JMeter proxy server to fail. One solution is to ensure that any files to be uploaded are in the JMeter working directory, either by copying the files there or by starting JMeter in the directory containing the files.
The HTTP Mirrror Server is a very simple HTTP server - it simply mirrors the data sent to it. This is useful for checking the content of HTTP requests.
The Property Display shows the values of System or JMeter properties. Values can be changed by entering new text in the Value column. It is available only on the WorkBench.
The Debug Sampler generates a sample containing the values of all JMeter variables and/or properties.
The values can be seen in the
The Debug PostProcessor creates a subSample with the details of the previous sampler properties. This is intended for developer use only.