jmeter-beanshell本地文件写入多列数据--for循环

1.  首先用一个请求,获取list数据;并且提取出来

  这里获取出来的是48个Name,id,color

 

 2.  使用beanshell取样器,循环次数 == ${goodsName_matchNr};可以从debug sample中查看

FileWriter fstream = new FileWriter("/jmeter/src/datacsv/goodsInfofor",true);
BufferedWriter out = new BufferedWriter(fstream);
//log.info(vars.get("goodsName_${__counter(true,)}").replace(" ","-"));for(int i=1; i<${goodsName_matchNr}+1; i++){
    goodsName_i = "goodsName_"+i;
//    log.info(goodsName_i);
    String goodsName = vars.get(goodsName_i).replace(" ","-");

    goodsId_i = "goodsId_"+i;
    String goodsId = vars.get(goodsId_i);

    goodsColorId_i = "goodsColorId_"+i;
    String goodsColorId = vars.get(goodsColorId_i);

    goodsColorName_i = "goodsColorName_"+i;
    String goodsColorName = vars.get(goodsColorName_i);
//    log.info(goodsName);
    
    out.write(goodsName+","+goodsId+","+goodsColorId+","+goodsColorName+"\n");
}
out.close();
fstream.close();

 

posted @ 2020-06-29 16:28  小心走火  阅读(105)  评论(0编辑  收藏