jmeter bean shell 脚本

import java.util.Random;
String counts=vars.get("count"); //获取关联值
String count2=vars.get("value");
if(Integer.valueOf(counts)<=0){
    log.info(counts);
    Failure = false;
    FailureMessage = "error";
    SampleResult.setSuccessful(false);
    }else {
//Random x =new Random();
//int rand1=x.nextInt(10)+1;  #nextInt(10) daibiaoshengcheng 0dao10de shu
//String string2="contractno_"+Integer.valueOf(rand1);
//log.info(vars.get(string2));
String string2="contractno_"+Integer.valueOf(count2);
vars.put("newcontractno",vars.get(string2)); //vars.get 是为了获取关联值

//String xxx="aaa";
//vars.put("newcontractno",xxx); //当要将一个变量推入关联名的时候。

}

 在获取一些比较特殊的参数的时候,如:线程名,线程号,线程组等等。这些不再是普普通通的var.get()了。

正确做法如下:

import test.Test;
import java.lang;
int threadnum=ctx.getThreadNum(); ###获取线程号
log.info("ddddddddddddddd"+String.valueOf(threadnum));
Test t =new Test();
log.info("transaction is"+t.run("C:\\Users\\Administrator\\Desktop\\t.txt",threadnum+1));
vars.put("transaction",t.run("C:\\Users\\Administrator\\Desktop\\t.txt",threadnum+1));

这就告诉了我们,bean shell 中,还有ampleResult, ResponseCode, ResponseMessage, IsSuccess, Label, FileName, ctx, vars, props, log 这些函数方法可以用,具体怎么用,还有待细查

 

posted on 2018-10-19 11:41  进_进  阅读(164)  评论(0)    收藏  举报