Jmeter

Conditions

${JMeterThread.last_sample_ok}

whether or not the last sample was OK - true/false. Note: this is updated after PostProcessors and Assertions have been run. 1

${__javaScript("${remaining}"!="0")}

Regular Expression Extractor

Json

"field" : "(.+?)"

XML

<MyElement myAttribute="(.+?)"/>

dynamic filenames for results

results/${__time(yyyy-MM-dd)}/${myProp}/run_${__time(HHmm)}.jtl

Stopping at any point

Use Test Action Target: All Threads Action: Stop Now

Debugging

Use Http sampler Name: ${var_to_output} server name: www.example.com

BeanShell

Passing details from one thread group to another

BeanShell Assertion

${__setProperty( propertyInNewThreadGroup, ${varInThisThreadGroup )};

Using this property

${__property(propertyInNewThreadGroup)}

General beanShell tips

var myVar = vars.get("myJmeterVar")
vars.put("booleanVar", "true")
vars.put("intVar", Integer.toString( 3 ));

Creating your own plug-in

This show an example Jmeter sampler plugin

Add the jar to you jmeter /lib/ext folder

package paulkane.jmeter.myplugin;

import org.apache.jmeter.samplers.AbstractSampler;
import org.apache.jmeter.samplers.Entry;
import org.apache.jmeter.samplers.SampleResult;
import org.apache.jmeter.testbeans.TestBean;

import java.io.UnsupportedEncodingException;
import java.time.Clock;

public class MyPlugin extends AbstractSampler implements TestBean {
    private static final String UTF_8 = "UTF-8";

    private String fieldOne;
    private String fieldTwo;

    @Override
    public SampleResult sample(Entry entry) {
        SampleResult sampleResult = new SampleResult();
        sampleResult.setSampleLabel(getName());
        //This displays as the Request
        sampleResult.setSamplerData(asJson(getFieldOne(), getFieldTwo());
        sampleResult.sampleStart();

        try {
            String result = performActionOn(getFieldOne(), getFieldTwo());

            sampleResult.setSuccessful(true);
            //This displays as the Response data
            sampleResult.setResponseData(asJson(result), UTF_8);
        } catch (UnsupportedEncodingException e) {
            sampleResult.setResponseData(e.getMessage(), UTF_8);
            sampleResult.setSuccessful(false);
        }

        sampleResult.setDataType(SampleResult.TEXT);
        sampleResult.sampleEnd();

        return sampleResult;
    }

    private String asJson(String fieldOne, String fieldTwo) {
        return String.format("{\n" +
            "  \"fieldOne\" : \"%s\",\n" +
            "  \"fieldTwo\" : \"%s\"\n" +
            "}", fieldOne, fieldTwo);
    }

    private String asJson(String result) {
        //outputting as json allows you to use Regular expression extractor on the result
        return String.format("{\n" +
            "  \"result\" : \"%s\"\n" +
            "}", result);
    }

    public String getFieldOne() {
        return fieldOne;
    }

    public void setFieldOne(String fieldOne) {
        this.fieldOne = fieldOne;
    }

    public String getFieldTwo() {
        return fieldTwo;
    }

    public void setFieldTwo(String fieldTwo) {
        this.fieldTwo = fieldTwo;
    }

}

1. 20.6 Pre-defined Variables

Last updated