This article will create a new function in Jmeter to achieve the replacement of the specified content in the text function. The result is as follows
1, eclipse project creation steps are omitted here, you can refer to a previousGetting Started with Jmeter Secondary Development Functions
2, a new class named "TextReplaceFunction", and inherit jmeter comes with the AbstractFunction
3, the new generation of documents inherited jmeter AbstractFunction brings out four methods, function development is in these four methods on the transformation
4., the complete code of the function realization is as follows
package ; import ; import ; import ; import ; import ; import ; public class TextReplaceFunction extends AbstractFunction { private final static String key="__TextReplace"; private static List<String> strParams=new LinkedList<String>(); static { ("original text(mandatory field)"); ("replaced content(mandatory field)"); ("Replace with(mandatory field)"); } public String originalText=""; public String text=""; public String ReplaceText=""; @Override public List<String> getArgumentDesc() { return strParams; } @Override public String execute(SampleResult arg0, Sampler arg1) throws InvalidVariableException { String result = (text, ReplaceText); return result; } @Override public String getReferenceKey() { return key; } @Override public void setParameters(Collection<CompoundVariable> arg0) throws InvalidVariableException { checkParameterCount(arg0,3); Object[] data=(); originalText=((CompoundVariable)data[0]).execute(); text=((CompoundVariable)data[1]).execute(); ReplaceText=((CompoundVariable)data[2]).execute(); } }
5, file right click export jar package
Select java->JAR file, click next
Save to jmeter installation directory \apache-jmeter-5.5\lib\ext\
6, restart jmeter, open the function assistant can see more than one TextReplace function
The ViewTextReplace function has 3 parameters
7, TextReplace function to use the effect of