Apache JMeter Basis

I’ve been doing some self-training for a few weeks. This time the choice fell on performance testing and specifically on a very interesting and useful open-source tool from Apache. I decided to write little guides on how to use it, so I will not forget this, and it will be helpful for some newcomers.

Test Plan Development

A key concept in the JMeter is Test Plan. Test Plan of application is the sequence of steps that will be executed by JMeter.
The test plan may contain:

Figure 1 shows that the element tree initially consists of two items: Test Plan and WorkBench.
WorkBench – this is a temporary item. Point is that the interface of Jmeter is built on “drag transfer” of elements in the tree scenario from one place to another. You create plan tree, and then can move its parts to the Workbench and vice versa.
Only contents of Test Plan is executed during testing, and the contents of Workbench is not even saved to disk.

Use the shortcut menu item “Test Plan” or the application main menu “Edit -> Add -> Script Element” for infill of Test Plan.

Thread Group Creating

Thread Group element lets you specify the parameters of workload generated to the application. Its main parameters are:

Number of threads – the number of simulated concurrent users working with the site;

Ramp-up period – the time interval to launch next process;

Loop count – the number of times the script will be executed within the Thread Group;

Forever – the script will be executed always, until it is terminated explicitly;

Scheduler – scheduling time of the script;

Action to be taken after a Sample Error – action to be performed after the request will cause an error.

For work with HTTP traffic JMeter provides element «HTTP Request». To create it you need to add an element «Thread Group» from the context menu for that item «Add» -> «Sampler ->« HTTP Request »(see Figure 6).

Figure 6

In the setting of request you must specify the following parameters:

Name – The name of the request

Server name or IP – address of the web server (URL or IP-address)

Port number – The port the web server (default 80)

Protocol – protocol (the default HTTP)

Method – A method of data transmission

Path – The path to the executable file on the server

Parameters – Transmit parameters and their values

To send a file in the request you must specify the parameter name and the file path in the section «Send files with request» (see Figure 7).

Figure 7

Data Driven Requests Creating

Parameters Transfer via Variables

In JMeter is possible to specify the request in terms of variables that are defined by the user. For these purposes, use the element «User Defined Variables».

In order to optimize duplicate data (for example, if you want to test multiple services located on one site), it is possible to specify default settings. You should add a HTTP Request Defaults to «Thread Group» from the context menu. Select «Add» -> «Config Element» -> «HTTP Request Defaults» (see Figure 15).

Figure 15

In the default settings for the «HTTP Request Defaults» you can specify:

* Server Name or IP – address of the web server (URL or IP-address)
* Port Number The port the web server (default 80)
* Protocol – protocol (the default HTTP)
* Path – The path to the executable file on the server
* Send Parameters with request – transmitted parameters and their values

All the following «HTTP Request» elements will take these settings by default, so the need to specify for each subsequent request these settings is eliminated.
Creating HTTPS Requests

JMeter proxy server is unable to handle traffic through HTTPS protocol. For these purposes, you can use third-party tools, such as the Badboy.For this write the script in BadBoy and take advantage of the function «File»> «Export to JMeter …» (see Figure 17).

Figure 17

However, it is worth remembering that there are enough elements of the Badboy script, which are not transferred to JMeter. Above all, actions recorded in Navigate mode, work with data sources (load data from excel-file), work with the schedule, etc. These actions need to be done in JMeter extra.

You can use can use the SSL Manager to work with the security certificates in JMeter:

1. Select the main menu «Options»> “SSL Manager” (Figure 19)

Figure 19

2. In the window that appears, select the certificate file in the format of p12 (see Figure 20)

Figure 20

3. During the test JMeter will ask you to specify a password for this certificate (see Figure 21)

Figure 21

In order to avoid the need to choose the certificate file at each start JMeter password and path to the certificate you can register only once in the configuration file system.properties.
To do this, follow these steps:

* In the bin directory of the root directory of JMeter open the file system.propeties
* Remove the comment from the lines and javax.net.ssl.keyStore javax.net.ssl.keyStorePassword, removing the symbol “#” at line
* Enter the line javax.net.ssl.keyStore path to the certificate, and in line javax.net.ssl.keyStorePassword its password

One of the most important functions of JMeter is a tool for distributed control – when you can run Jmeter on several machines, but the management of these JMeter copies is executed from one central computer.

To configure distributed testing it is necessary to perform the following steps: