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:
- JMeter Docker Image
- Test scripts and Data files
- JMeter test run command
Benefits
S. No. | No Need To | Instead Of That |
---|---|---|
1 | Install JMeter in a conventional way | Use the Docker Pull command to install the JMeter image |
2 | Update the user.properties and jmeter.properties files for every test machine | Test Tool uniformity is achieved across all machines on which the JMeter image is installed |
3 | Download the JMeter from the Apache site | Use as much as JMeter images available on the Docker HUB |
4 | Launch JMeter, and open test scripts to run load tests | Open the DOCKER CLI and hit the docker run command |
5 | Move test data file paths from system to system | Auto managed by one time set up of Folder structure and using Docker Volume Workspace |
6 | Set-up is exhaustive for non-Jmeter teams | Easy 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):
- System: Windows / Mac OS
- 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
- 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.
- Software: Docker Desktop & Windows PowerShell (pre-installed with OS)
- 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
- Repository: GitHub Repository Set up
- Upload the Project – test scripts to a version repository such as GitHub.
- This repository will be used to share test scripts with development or any remote teams
- For this article, some sample test scripts are placed in the given GitHub URL. https://github.com/swethapn/blazeDemo
- Folder Structure:
- Create the below folders structure in the C directory of your machine
- jmeter-base (Root Folder)
- 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).
- Create the below folders structure in the C directory of your machine
- Pull JMeter Image
- 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 - 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.
- 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:
Test Execution Steps
- Download GitHub Scripts
- 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 - Remote or Development teams to download the test scripts from the GitHub repository/SharePoint to the local path
- TestBlazedemo can be downloaded from my public GIT repository: https://github.com/swethapn/blazeDemo
- Place your JMeter/JMX test scripts in the local folder. The local folder is the same which you created in pre-requisite Step 4
- PowerShell CLI
- Run the JMeter Command to execute Load tests against the test script
- 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
- JMeter Attributes:
- Jthreads – Number of users for the load test
- Jrampup – The time for the users to initiate (in seconds)
- Change the test script when needed
- Log file’s name to change every test run
- Html report name to change for every test run
- Test Results
- 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.
- Example: C:/jmeter-base/html/10VuReport/index.html
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 Segment | Meaning | To be changed |
---|---|---|
docker run | To command docker to run a test | Do not change |
-v C:/jmeter-base:/workspace | Setting 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:JmeterLatest | Refer to Figure 04 in pre-requisite Step 5 | Change if pulling a different JMeter image |
Arguments | Meaning | Example | To be changed |
---|---|---|---|
-Jthreads | This is a JMeter argument to input the number of users | 10 | To be changed as per requirement |
-Jrampup | This is a JMeter argument to input user ramp-up rate | 20 | To be changed as per requirement |
-n | This is a JMeter argument to run the test in Non-GUI mode | NA | Do not change |
-t | This is a JMeter argument with the JMX path. It points to the script placed in the workspace location. | -t /workspace/TestBlazedemo/Blazedemo.jmx | Text in Bold: To be changed, depending on the script/file names |
-l | This is a JMeter argument with a log file path to save the test logs | -l /workspace/logs/Blazedemo_10Vu.jtl | Text in Bold: To be changed, depending on the log file name/path |
-e | This is a JMeter argument to generate the HTML report automatically just after the completion of the test | NA | Do not change |
-o | This 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/10VuReport | Text in Bold: To be changed, depending on the output file path |
-H | This is a JMeter argument to specify the proxy host | -H proxy.xxx.com | Update Accordingly |
-P | This is a JMeter argument to specify the proxy port | -P 3120 | Update 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
- CSV file Path
- 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
Recap
The above steps allow developers/team members to do one of the following:
- Novice
- Pull JMeter image from Docker hub
- Download JMeter scripts(latest from GitHub project repository)
- Run the test by changing the # of users and # ramp-up time
- Expert
- Edit scripts after downloading from GitHub as the scripts will be in the local workspace
- Novice
- View reports in html folder after the test completes
- Analyze and log bugs
You may be interested:
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?
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!