进行用来调试的组件:Debug Sampler、BeanShell Sampler
public static void test() { String input; input = vars.get("aa"); String output = "hello," + input; vars.put("bb", output); } test();
代码
public static void test() {
String input;
input = vars.get("aa");
String output = "hello," + input;
vars.put("bb", output);
}
test();
通过source关键字进行导入java文件
有包没包的处理情况相同
有包路径的java文件
package fengluo; public class BeanShellMethod { public static String name(String input) { String result = ""; result = result + "hello," + input; return result; } }
没有包路径的java文件
public class BeanShellMethod2 { public static String name(String input) { String result = ""; result = result + "hello," + input; return result; } }
代码
source("F:\\@0601____project____jmeter\\BeanShellMethod.java");
String input = vars.get("aa");
//String output = new BeanShellMethod().name(input);
String output = BeanShellMethod.name(input);
vars.put("dd", output);
代码
addClassPath("F:/@0601____project____jmeter");
//from fengluo import BeanShellMethod;
import fengluo.BeanShellMethod;
//import BeanShellMethod2;
String input = vars.get("aa");
//String output = new BeanShellMethod2().name(input);
String output = BeanShellMethod.name(input);
vars.put("dd", output);
jar文件放入ext路径中(F:\Jmeter\apache-jmeter-4.0\lib\ext)
放入的文件可以进行自己命名
代码
//from fengluo import BeanShellMethod;
//import BeanShellMethod2;
import fengluo.BeanShellMethod;
String input = vars.get("aa");
String output = new BeanShellMethod().name(input);
vars.put("dd", output);
java文件 jar
import java.io.IOException; import java.io.UnsupportedEncodingException; import sun.misc.BASE64Decoder; import sun.misc.BASE64Encoder; public class Base64 { public static void main(String[] args) throws IOException { // TODO 自动生成的方法存根 //System.out.println(Base64.encode("123123")); //System.out.println(Base64.decode("MTIzMTIz")); } public static String encode(String input) throws UnsupportedEncodingException { byte[] i; i = input.getBytes("utf-8"); String output = new BASE64Encoder().encode(i); return output; } public static String decode(String input) throws IOException { byte[] aa = new BASE64Decoder().decodeBuffer(input); String output = new String(aa, "utf-8"); return output; } }
代码
//import fengluo.BeanShellMethod;
import Base64;
String input = vars.get("aa");
String output = Base64.encode(input);
vars.put("aa", output);
代码
//import fengluo.BeanShellMethod;
import Base64;
String input = vars.get("aa");
String output = Base64.decode(input);
vars.put("aa", output);
原文:https://www.cnblogs.com/wujianbo123/p/10886289.html