Skip to content

JSR223 Groovy Playground & Code Builder

Lint JMeter-specific Groovy anti-patterns, inspect JSR223 bindings, and generate ready-to-paste JMX elements from curated recipes or custom scripts.

Difficulty
intermediate
Guide type
reference
Estimated read time
6 min read
Bindings Used-
Errors-
Warnings-
Lines-

Static Analysis

Bindings for Selected Element

Groovy Script (.groovy)

JMX Element Snippet

Paste into a .jmx under the target sampler's <hashTree>, or import via JMeter GUI โ†’ Edit โ†’ Paste.

Use Groovy tools through MCP

Call get_jsr223_recipe for curated examples, or lint_groovy_script to review your own code and generate JSR223 element XML.

claude mcp add jmeter-docs https://docs.jmeter.ai/api/mcp --transport http

This builder does not execute Groovy. Review generated code and run it in a controlled JMeter test before load testing. See JSR223 Sampler Reference and JMeter MCP Reference.

JMeter supports Groovy through JSR223 compilation caching, while BeanShell is interpreted and substantially slower in a hot sampling path. Groovy also provides modern Java interoperability, mature JSON support, and access to JMeterโ€™s documented script bindings.

This page is a builder and static analyzer. Groovy cannot execute in the browser. The tool inspects source text for JMeter-specific pitfalls and generates files for you to review and run in JMeter; it does not validate runtime types, external classes, network access, or script behavior.

Every JSR223 element exposes the common bindings log, Label, FileName, Parameters, args, ctx, vars, props, and OUT. Element-specific bindings differ:

ElementAvailable bindings
JSR223 Samplerlog, Label, FileName, Parameters, args, ctx, vars, props, OUT, SampleResult, sampler
JSR223 PreProcessorlog, Label, FileName, Parameters, args, ctx, vars, props, OUT, sampler
JSR223 PostProcessorlog, Label, FileName, Parameters, args, ctx, vars, props, OUT, sampler, prev
JSR223 Assertionlog, Label, FileName, Parameters, args, ctx, vars, props, OUT, SampleResult, AssertionResult, prev, sampler
JSR223 Timerlog, Label, FileName, Parameters, args, ctx, vars, props, OUT, sampler
JSR223 Listenerlog, Label, FileName, Parameters, args, ctx, vars, props, OUT, sampleResult, prev, sampleEvent, sampler

Binding names are case-sensitive. For example, SampleResult is available in a Sampler or Assertion, while lowercase sampleResult and sampleEvent belong to a Listener. prev is available to PostProcessors, Assertions, and Listeners, but not PreProcessors or Timers; sampler is available to all six element types, including Listeners.

Rule IDSeverityWhat it catches
EMPTY_SCRIPTErrorBlank code
THREAD_SLEEPErrorThread.sleep(...) or sleep(...) blocking a JMeter worker thread
JMETER_VAR_INTERPOLATIONWarning${name} expansion without a preceding Groovy local declaration
SYSTEM_OUTWarningSystem.out, System.err, or statement-level println(...)
NEW_RANDOM_PER_CALLInfoA new Random instance created on each invocation
REGEX_COMPILE_IN_SCRIPTInfoPattern.compile(...) in the hot script path
UNAVAILABLE_BINDINGErrorA known binding used by the wrong JSR223 element type
BEANSHELL_IMPORTErrorBeanShell imports or API references inside Groovy
LEGACY_JSONSLURPER_CLASSICInfoJsonSlurperClassic instead of JsonSlurper
PROPS_MUTATION_IN_LOOP_HOT_PATHInfoWrites to shared JMeter properties with props.put(...)
SCRIPT_TOO_LONGWarningInline code over 200,000 characters that belongs in a .groovy file

For dynamic JMeter values, prefer vars.get("name") or props.get("name"). Substitution such as ${token} happens before Groovy compilation, can create a new compiled script for each value, and can break syntax when data contains quotes or other special characters.

  1. Select the JSR223 element that matches where the script should run.
  2. Fix error-level binding or scripting findings.
  3. Copy the generated element and its following <hashTree/>.
  4. Paste it under the target elementโ€™s <hashTree> in the .jmx, or use JMeter GUI โ†’ Edit โ†’ Paste.
  5. Open the plan in JMeter, confirm the tree location, and run a one-user smoke test with assertions before applying load.

The generated element uses TestBeanGUI, Groovy, and a non-empty cacheKey so JMeter can cache compiled scripts. Downloading the .groovy variant is useful when scripts are shared across plans or maintained in source control; set that file through the JSR223 FileName field in JMeter.

Connect an MCP-compatible agent:

Terminal window
claude mcp add jmeter-docs https://docs.jmeter.ai/api/mcp --transport http

Ask the agent to call get_jsr223_recipe by recipe name or category to retrieve the curated JWT, HMAC, dynamic header, JSON extraction, and custom logging examples used by this builder. For your own script, call lint_groovy_script with the code and JSR223 element type to receive the same findings, binding analysis, and optional ready-to-paste JMX element XML.

On this page