Next Practical Step
Take any red sampler from a recorded plan and replace one hard-coded ID with a Regex or JSON extractor end-to-end.
End-to-end JMeter correlation: extract CSRF tokens, session IDs, and JSON fields with Regex and JSON extractors, chain requests, and debug replays.
Correlation means capturing a value from one response and reusing it in later requests so a multi-step flow works under many threads. Without it, recorded scripts fail on replay: session IDs, CSRF tokens, order IDs, and JWTs change every run. This guide walks through extractors, variable scope, chaining patterns, debugging, and load-safe practice, grounded in JMeter regular expressions, functions and variables, best practices, and the component reference.
The HTTP(S) Test Script Recorder captures literal values from your session. On the next run the server issues new secrets. Typical dynamic fields:
state, nonce, codeaccess_tokenorderId, cartId)Cookies are correlated automatically if the Cookie Manager is present. Everything else needs post-processors (extractors) or explicit functions.
\${varName}.NOT_FOUND) on the extractor.| Tool | Best for |
|---|---|
| JSON Extractor | REST JSON bodies (access_token, nested ids) |
| Regular Expression Extractor | HTML snippets, headers, mixed text |
| CSS Selector Extractor | HTML elements when CSS queries fit |
| XPath Extractor | XML / some HTML (costlier; use carefully under load) |
| Boundary Extractor | Fixed left/right text boundaries |
| Cookie Manager | Set-Cookie / Cookie headers |
For JSON APIs, prefer structured JSON extraction over fragile full-body regex when possible. For free text, regex remains standard; see the regular expressions chapter.
Documented concepts you will set on every regex extractor:
| Field | Role |
|---|---|
| Name of created variable | e.g. csrfToken → \${csrfToken} |
| Regular Expression | Pattern with capture groups (...) |
| Template | $1$ for first group, $0$ full match |
| Match No. | 1 first match; 0 random; negative for all + _matchNr |
| Default Value | Used when no match (debug signal) |
Example HTML:
<input type="hidden" name="_csrf" value="a1b2c3d4" />Pattern (illustrative):
name="_csrf"\s+value="([^"]+)"Template: $1$ → variable holds a1b2c3d4.
Build candidates faster with the Regex Extractor Builder (paste response locally in the browser; nothing is uploaded).
Login response:
{"access_token":"eyJ...","order":{"id":"ORD-9"}}accessToken, path to token.orderId if supported by your element setup.Authorization: Bearer \${accessToken}./orders/\${orderId}.Always assert login success so empty tokens do not flood the next step.
From the functions manual:
\${orderId} by default.\${__P} / __setProperty). Use for environment config, not per-user secrets under load.\${name} is returned unchanged (no hard error). That is why defaults and assertions matter.Extractors run as post-processors after their parent sampler (and according to scope rules in the tree). Put the extractor under the sampler that returns the value, not under a later sibling that never sees the response.
Login → extract tokenCreate cart → extract cartIdAdd item → use cartIdCheckout → extract orderIdGet order → use orderIdUse Transaction Controllers to group steps for dashboard reporting (dashboard). Keep sampler labels stable (Login, CreateCart) so series and filters stay readable.
\${accessToken} equals default failure value.| Mechanism | Element |
|---|---|
| Session cookie | HTTP Cookie Manager |
| CSRF in HTML form | Regex / CSS / Boundary extractor → form parameter |
| Bearer token | Header Manager + variable |
| Query parameter id | Path or parameters field \${id} |
Missing Cookie Manager is a top cause of “works in browser during record, fails in JMeter.”
Best practices: use as few assertions as needed under load; avoid heavy listeners. Same idea for extractors:
In distributed mode, each worker is a separate JVM. Per-thread variables stay on that worker. CSV files used for users must exist on each worker (not auto-copied). Do not assume a property set on one engine is visible on another.
| Mistake | Result |
|---|---|
| Hard-coded recorded token | Immediate or mid-test auth failures |
| Extractor on wrong sampler | Empty variable |
| No default value | Silent empty strings |
Regex without group but template $1$ | Wrong or empty |
| Match No. wrong | Picks stale or random match |
| Sharing tokens via properties | Cross-talk between users |
| Skipping Cookie Manager | Session lost |
\${...} literals in failures.Capturing dynamic values from responses (tokens, IDs) into variables and sending them on later requests so multi-step scenarios work for every thread.
For JSON responses, prefer JSON-oriented extractors. Use regular expressions for HTML fragments, headers, or unstructured text.
\${csrf}?The variable was never set. JMeter leaves undefined references unchanged. Fix the extractor and use a default value to detect misses.
Cookies often work automatically with Cookie Manager. Body and header tokens still need extractors.
Not with ordinary variables. Variables are thread-local by design. Use properties only for intentional global data, not per-user IDs.
Replay with one thread, find the first failure, extract from the previous response, replace hard-coded values, and repeat until green.
On this page