Scripting Guide · Apache JMeter

Steps for JMeter Scripting

A structured process to create reliable, reusable, and realistic performance test scripts that simulate real user behavior.

Realistic Scalable Reusable Stable
End-to-End Scripting Flow
Requirement
Environment Setup
Test Plan
Thread Group
Add Requests
Correlation
Parameterization
Assertions
Debug
Dry Run
CLI Exec
Report
01

Preparation & Environment Setup

🛠️

Install Java (JDK 11+)

java -version
📦

Download & Launch JMeter

Windows: jmeter.bat
Linux/Mac: ./jmeter.sh
🎯

Define Test Objectives

Expected LoadResponse Time SLATPS TargetTest DurationBusiness Transactions
Login API should respond within 2 seconds for 1,000 concurrent users.
02

Building the Test Plan Structure

📐
👥

Add Thread Group

ParameterValueMeaning
Threads100Virtual Users
Ramp-Up50 secTime to start all users
Loop Count10Each user repeats 10×
⚙️

Add Config Elements

ElementPurpose
HTTP Request DefaultsDefault server details
HTTP Header ManagerContent-Type, Auth headers
HTTP Cookie ManagerSession handling
CSV Data Set ConfigTest data parameterization
Tip: Configure server URL once in HTTP Request Defaults instead of repeating in every sampler.
03

Creating Samplers (Requests)

📡
✍️

Manual Entry

Thread Group → Add → Sampler → HTTP Request
FieldValue
MethodPOST
Path/login
Bodyusername=test
🔴

Recording

HTTP(S) Test Script Recorder captures browser traffic automatically.
1. Configure proxy 2. Set browser proxy 3. Install SSL cert 4. Navigate app 5. Auto-capture
04

Enhancing the Script

Recorded scripts are static. Enhancement makes them realistic and reusable — correlation, parameterization, assertions, and timers.
🔗

Correlation

Capture dynamic values (Session ID, CSRF Token, JWT) from one request and use in the next.
Response: {"token":"abc123xyz"}
JSON Extractor → ${token}
Next Request Header: Authorization: Bearer ${token}
📊

Parameterization

Use external test data via CSV Data Set Config instead of hardcoded values.
CSV: username,password
user1,pass1
user2,pass2
→ Each VU picks unique data

Assertions

Validate response correctness — not just HTTP 200, but actual content.
AssertionPurpose
Response AssertionValidate text content
Duration AssertionValidate response time
JSON AssertionValidate JSON fields
Size AssertionValidate payload size
⏱️

Timers

Simulate real-user think time between requests.
TimerPurpose
Constant TimerFixed delay (e.g., 5 sec)
Gaussian RandomRealistic random delay
Uniform RandomRandomized wait range
05

Debugging & Validation

🔍
🌳

View Results Tree

Inspect request/response, headers, variables, errors. Verify ${token} is correctly captured.
🧪

Dry Run (1 User)

Execute with 1 user before large-scale runs.
Login works ✓ Correlation works ✓ Data picks ✓ Assertions pass ✓
1 User = Functional validation · 1,000 Users = Performance testing
06

Test Execution & Best Practices

🚀
💻

Execute in CLI Mode (Non-GUI)

GUI consumes CPU/memory and reduces JMeter performance. Always use CLI for load tests.
jmeter -n -t TestPlan.jmx -l results.jtl
🚫

Disable Heavy Listeners

Avoid View Results Tree / Table during load tests — they consume huge memory and may crash JMeter.
🧠

Heap Memory Tuning

Increase JVM heap for large tests. Edit jmeter.bat or jmeter.sh:
HEAP=-Xms2g -Xmx4g
→ Initial: 2 GB · Max: 4 GB
📊

Generate HTML Report

jmeter -g results.jtl -o ReportFolder

Scripting Summary

StepPurpose
Environment SetupPrepare Java & JMeter
Test Plan CreationThread Group, Config Elements
Sampler CreationManual entry or recording
EnhancementCorrelation, parameterization, assertions, timers
Debug & ValidateResults Tree, dry run with 1 user
ExecutionCLI mode, heap tuning, HTML report