Class DslVariables

  • All Implemented Interfaces:
    DslConfig, DslTestElement, DslTestPlan.TestPlanChild, BaseSampler.SamplerChild, MultiLevelTestElement, BaseThreadGroup.ThreadGroupChild

    public class DslVariables
    extends BaseConfigElement
    Allows setting JMeter thread variables that can be used later on in JMeter expressions or JSR223 scripts.

    When you only need to reuse some string or value, prefer using java variables instead of creating jmeter variables, which is easier to maintain, and makes the test plan more efficient (fewer variables in memory).

    This internally uses JMeter User Defined Variables element when variables are included at test plan level, but uses JSR223 sampler otherwise to provide more consistency and avoid confusion generated by User Defined Variables semantics (like non reinitialization in threads iterations, vars cross-references, vars scope, etc. Check red blocks comments in JMeter component documentation).

    Since:
    0.50
    • Constructor Detail

      • DslVariables

        public DslVariables()
      • DslVariables

        public DslVariables​(String name)
    • Method Detail

      • set

        public DslVariables set​(String varName,
                                String varValue)
        Allows setting a JMeter thread variable.

        When the variable is set at test plan level, one variable for each thread group is created at test plan start with given name and value. When inside a thread group, controller, etc, it will only be created/updated with given value when such point in test plan is reached.

        Parameters:
        varName - specifies the name of the variable to register. This can be a literal value (eg: "test") or a JMeter expression (eg:
        ${VAR_NAME}
        ).
        varValue - specifies the value associated to the variable. This can be a literal value (eg: "test") or a JMeter expression (eg:
        ${VAR_VALUE}
        ).
        Returns:
        the DslVariables instance for further configuration or usage in test plan.
      • buildTreeUnder

        public org.apache.jorphan.collections.HashTree buildTreeUnder​(org.apache.jorphan.collections.HashTree parent,
                                                                      BuildTreeContext context)
        Description copied from interface: DslTestElement
        Builds the JMeter HashTree for this TestElement under the provided tree node.
        Specified by:
        buildTreeUnder in interface DslTestElement
        Overrides:
        buildTreeUnder in class BaseTestElement
        Parameters:
        parent - the node which will be the parent for the created tree.
        context - context information which contains information shared by elements while building the test plan tree (eg: adding additional items to test plan when a particular protocol element is added).
        Returns:
        The tree created under the parent node.