JMeter – Docker Test Executions

Written By: Swetha Pujari

Introduction

JMeter tests can be done on GUI and non-GUI in a headless front, both of which are easy to set up for JMeter enthusiasts.

However, there are instances where developers/remote stakeholders/shared testing teams have to execute the Performance tests on different machines.

Even when the testing team does not have any reservations about sharing the testing scripts, the knowledge transfer on how to execute Jmeter scripts is an exhaustive process. There is so much to hand over from test data, folder structures, understanding active listeners, and finally, the execution set-up. So, how do make things simple?

Solution

To make the handover simple, one can execute JMeter test scripts via Dockers. It reduces the effort of setup significantly for both parties involved.

Only three things are required to get things moving:

  1. JMeter Docker Image
  2. Test scripts and Data files
  3. JMeter test run command

Benefits

S. No.No Need ToInstead Of That
1Install JMeter in a conventional wayUse the Docker Pull command to install the JMeter image
2Update the user.properties and jmeter.properties files for every test machineTest Tool uniformity is achieved across all machines on which the JMeter image is installed
3Download the JMeter from the Apache siteUse as much as JMeter images available on the Docker HUB
4Launch JMeter, and open test scripts to run load testsOpen the DOCKER CLI and hit the docker run command
5Move test data file paths from system to systemAuto managed by one time set up of Folder structure and using Docker Volume Workspace
6Set-up is exhaustive for non-Jmeter teamsEasy to handover whenever any remote teams want to execute a specific load test against the Application under test

Step-by-Step Guide

In a few easy steps, you can execute your first JMeter load test run using Dockers in the local machine.

Please note that this article does not discuss what is Docker and the inner workings of Docker in the interest of keeping the article short and crisp.

Pre-requisites (One Time Activity):

  1. System: Windows / Mac OS
    1. The demonstration has been given by using a Windows Machine for the setup. The process to set up on Mac OS is also pretty straightforward
    2. You must have power user or admin rights on the PC. This is optional but good to have the admin right to avoid unusual restrictions.
  2. Software: Docker Desktop & Windows PowerShell (pre-installed with OS)
    1. Install the latest version of Docker Desktop on your Windows machine. Refer to the below URL: https://hub.docker.com/editions/community/docker-ce-desktop-windows
  3. Repository: GitHub Repository Set up
    1. Upload the Project – test scripts to a version repository such as GitHub.
    2. This repository will be used to share test scripts with development or any remote teams
    3. For this article, some sample test scripts are placed in the given GitHub URL. https://github.com/swethapn/blazeDemo
  4. Folder Structure:
    1. Create the below folders structure in the C directory of your machine
      1. jmeter-base (Root Folder)
      2. Under this create 3 sub-folders (Refer to Figure 02)
        • html
        • logs
        • Project Folder (say TestBlazedemo) – In this folder, test-related files like JMX, CSV, PDF are saved (Refer to Figure 03).
JMeter – Docker Test Executions Figure 02
Figure 02
JMeter – Docker Test Executions - Figure 03
Figure 03
  1. Pull JMeter Image
    1. In this step, you have to pull the Docker Image of JMeter instead of installing it from the Apache site. You can pull the JMeter image by Launching PowerShell CLI and executing the command to download JMeter Image. The command is:
      docker pull swethapn14/repo_perf:JmeterLatest
    2. This is also one-time activity. You should see a message that the Pull is successful. As I already have it, I see that the image is up to date.
JMeter – Docker Test Executions - Figure 04
Figure 04

Test Execution Steps

  1. Download GitHub Scripts
    1. Place your JMeter/JMX test scripts in the local folder. The local folder is the same which you created in pre-requisite Step 4
      Example: C:/jmeter-base/TestBlazedemo
    2. Remote or Development teams to download the test scripts from the GitHub repository/SharePoint to the local path
    3. TestBlazedemo can be downloaded from my public GIT repository: https://github.com/swethapn/blazeDemo
  2. PowerShell CLI
    1. Run the JMeter Command to execute Load tests against the test script
    2. docker run-v C:/jmeter-base:/workspace swethapn14/repo_perf:JmeterLatest -Jthreads=10 -Jrampup=20 -n -t /workspace/TestBlazedemo/Blazedemo.jmx -l /workspace/logs/Blazedemo_10Vu.jtl -e -o /workspace/html/10VuReport
    3. JMeter Attributes:
      1. Jthreads – Number of users for the load test
      2. Jrampup – The time for the users to initiate (in seconds)
      3. Change the test script when needed
      4. Log file’s name to change every test run
      5. Html report name to change for every test run
Figure 05
  1. Test Results
    1. Once the test is completed then go to the ‘html’ folder given in the command and find the index.html to view the test results.
    2. Example: C:/jmeter-base/html/10VuReport/index.html
Figure 06

JMeter Command Explained

JMeter command to execute test runs via Docker is

docker run -v C:/jmeter-base:/workspace swethapn14/repo_perf:JmeterLatest -Jthreads=10 -Jrampup=20 -n -t /workspace/TestBlazedemo/Blazedemo.jmx -l /workspace/logs/Blazedemo_10Vu.jtl -e -o /workspace/html/10VuReport

The command does the work needed to execute a load test with ‘10’ users that will ramp up in ‘20’ seconds. The users inject traffic on the test script Blazedemo.jmx and write the results to a log file named Blazedemo_10Vu.jtl. After the test finishes, the JMeter HTML report will be automatically generated & placed in the html/10VuReport folder in the workspace (i.e. C:/jmeter-base)

Command SegmentMeaningTo be changed
docker runTo command docker to run a testDo not change
-v C:/jmeter-base:/workspaceSetting up a docker volume to connect your local C drive to the docker workspace

–Local drive–
C:/jmeter-base:/workspace
(Do not change unless you have a different folder structure)

–Note–
Your local C:/jmeter-base folder is called as workspace going forward. This folder contains the test scripts, test data files and PDFs for any upload functionality.
Do not change unless the folder path in your system is different
swethapn14/repo_perf:JmeterLatestRefer to Figure 04 in pre-requisite Step 5Change if pulling a different JMeter image
ArgumentsMeaningExampleTo be changed
-JthreadsThis is a JMeter argument to input the number of users10To be changed as per requirement
-JrampupThis is a JMeter argument to input user ramp-up rate20To be changed as per requirement
-nThis is a JMeter argument to run the test in Non-GUI modeNADo not change
-tThis is a JMeter argument with the JMX path. It points to the script placed in the workspace location.-t /workspace/TestBlazedemo/Blazedemo.jmxText in Bold: To be changed, depending on the script/file names
-lThis is a JMeter argument with a log file path to save the test logs-l /workspace/logs/Blazedemo_10Vu.jtlText in Bold: To be changed, depending on the log file name/path
-eThis is a JMeter argument to generate the HTML report automatically just after the completion of the testNADo not change
-oThis is a JMeter argument to specify the path of the generated HTML report
 
After the test run completes, visit the ‘html’ folder and open the index.html for analysing the test result
-o /workspace/html/10VuReportText in Bold: To be changed, depending on the output file path
-HThis is a JMeter argument to specify the proxy host-H proxy.xxx.comUpdate Accordingly
-PThis is a JMeter argument to specify the proxy port-P 3120Update Accordingly

Command to execute JMeter tests on Proxy with Security Layer

docker run -v C:/jmeter-base:/workspace swethapn14/repo_perf:JmeterLatest –H proxy.xxx.com –P 3120 -Dhttps.protocols=TLSv1,TLSv1.1,TLSv1.2 -Jthreads=10 -Jrampup=20 -n -t /workspace/TestBlazedemo/TestScriptName.jmx -l /workspace/logs/ProjectName_testEnv_Datetime_NoOfVu_Vu.jtl -e -o /workspace/html/TestReportName_NoOfVu_Project_Report

– H proxy.xxx.com –P 3120 : The Host and Port on which the Proxy of your Organization is set up

– Dhttps.protocols=TLSv1,TLSv1.1,TLSv1.2 : Transport Layer security to access the Application under test

Pointers on CSV Data Set Config – TestData

CSV Data Set configs are popularly used to feed test data to JMeter scripts. It is included in the Test Plan and contains a mapping to the CSV file location. Please note that there are a couple of pointers to note for executions on Docker vs executions in JMeter GUI.

Keep a look out on the forward and backward slashes (‘/’ ‘\’) in the file paths specified

  • Docker Executions
    • CSV file Path
      • The path should be mapped to the Docker volume
      • /workspace/<ProjectName>/<Filename.csv>
      • Example: /workspace/TestBlazedemo/TestData.csv
Figure 07
  • For JMeter GUI Test Runs
    • CSV File Path should point to the Windows C:/ folder path
    • C:\jmeter-base\<ProjectName>\<Filename.csv>
    • Example: C:\jmeter-base\TestBlazedemo\TestData.csv
Figure 08

Recap

The above steps allow developers/team members to do one of the following:

  1. Novice
    1. Pull JMeter image from Docker hub
    2. Download JMeter scripts(latest from GitHub project repository)
    3. Run the test by changing the # of users and # ramp-up time
  2. Expert
    1. Edit scripts after downloading from GitHub as the scripts will be in the local workspace
  3. Novice
    1. View reports in html folder after the test completes
    2. Analyze and log bugs

You may be interested:


2 thoughts on “JMeter – Docker Test Executions”

  1. Hi Swetha,

    Getting below error when I run docker jmeter command.

    PS C:\Users\busvxs> docker run-v C:/jmeter-base:/workspace swethapn14/repo_perf:JmeterLatest -Jthreads=10 -Jrampup=20 -n -t /workspace/scripts/BCA_Browse_02.jmx -l /workspace/logs/jmeter-bca-test_10Vu.jtl -e -o /workspace/html/10VuReport unknown shorthand flag: ‘J’ in -Jthreads=10
    See ‘docker –help’.

    unknown shorthand flag: ‘J’ in -Jthreads=10
    See ‘docker –help’.

    Any suggestions?

  2. Hi Jaish, Thanks for your message.
    Please help to answer the following to better understand the issue and exclude any varying paramters:-
    * Which OS are you using MAC or Windows; if windows, mention the OS version
    * Which Command Line Interface are you using to interact with Dockers (Terminal or PowerShell CLI or
    anything else?)
    * Is the JMeter image pulled from the command recommended in the article :

    A quick solution is to remove the -J tags(which are optional to edit the user load and rampup) and try executing the run command but I have my doubts if its would result in the exepected run , but no harm in giving a shot.

    Note: If you need personal assistance, kindly drop a message on my Linkedin @https://www.linkedin.com/in/swetha-pn/ and we can take it from there!

Comments are closed.