jmete JSR223 PostProcessor使用

1.使用xpath Extractor提取页面值

 

2.使用 JSR223 PostProcessor拼接json数据

function genJsons() {
	var MaterialName = vars.get("MaterialName");
	var cnt = vars.get("supplierMaterialId_matchNr");
	var tabs = "\t";
	var actualQuantity="";
	var deliveryAttr="";
	var id1 = "";
	var supplierMaterialId = "";
	var supplyId = "";
	var materialId = "";
	var secondNum = "";
	var supplierMaterialName = "";
	var spce="";
	var amountUnit="";
	var otherQuantity="";
	var supplierMaterialUnits="";
	var rtn = "";
	var supplyName="";
	for (var i=1; i <= cnt; i++) {
		id1 = vars.get("id1_" + i);
		supplierMaterialId = vars.get("supplierMaterialId_" + i );
		supplyId = vars.get("supplyId_" + i );
		materialId = vars.get("materialId_" + i );
		secondNum = vars.get("secondNum_" + i );
		supplierMaterialName = vars.get("supplierMaterialName_" + i );
		actualQuantity=vars.get("actualQuantity_"+i);
		deliveryAttr=vars.get("deliveryAttr_"+i);
		spce=vars.get("spce_"+i+"_g1");
		if(spce==null)
		spce="";
		amountUnit=vars.get("amountUnit_"+i);
		otherQuantity=vars.get("otherQuantity_"+i);
		supplierMaterialUnits=vars.get("supplierMaterialUnits_"+i);
		amountUnit=vars.get("amountUnit_"+i);
		otherQuantity=vars.get("otherQuantity_"+i);
		supplyName=vars.get("supplyName_"+i);
			if(actualQuantity==0&&supplierMaterialUnits=="公斤")
			{
			actualQuantity=1;
			otherQuantity=1;
			}
//		if(supplierMaterialUnits=="包")
//	       supplierMaterialUnits="\n\t\t\t\t\t\t\t\t\t\t\t\t\t包\n\t\t\t\t\t\t\t";
//		else if(supplierMaterialUnits=="公斤")
//		  supplierMaterialUnits="\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t公斤\n\t\t\t\t\t\t\t";
		log.info("cnt:" + i);
		log.info("id1:" + id1);
		log.info("supplierMaterialId:" + supplierMaterialId);
		log.info("supplyId:" + supplyId);
		log.info("materialId:" + materialId);
		log.info("secondNum:" + secondNum);
		log.info("supplierMaterialName:" + supplierMaterialName);
	rtn = rtn + "{\"actualQuantity\":\""+actualQuantity+"\"," + "\n" +
		tabs + "\"deliveryAttr\":\""+deliveryAttr+"\"," +  "\n" +
		tabs + "\"supplierMaterialId\":\"" + supplierMaterialId + "\"," + "\n" +
		tabs + "\"id\":\"" + id1 +"\"," + "\n" +
		tabs + "\"supplyId\":\"" + supplyId + "\"," + "\n" +
		tabs + "\"materialId\":\"" + materialId +  "\"," + "\n" +
		tabs + "\"secondNum\":\"" + secondNum + "\"," + "\n" +
		tabs + "\"supplierMaterialName\":\"" + supplierMaterialName + "\"," + "\n" +
		tabs + "\"spce\":\""+spce+"\"," + "\n" +
		tabs + "\"amountUnit\":\""+amountUnit+"\"," + "\n" +
		tabs + "\"otherQuantity\":\""+otherQuantity+"\"," + "\n" +
		tabs + "\"supplierMaterialUnits\":\""+supplierMaterialUnits+"\"," + "\n" +
		tabs + "\"supplyName\":\""+supplyName+"\"" + "\n" +
		tabs + "},"+"\n"
	}
	//return rtn;	
	log.info(rtn);
	var rtns=rtn.substring(0,rtn.length-2);
	//var rtns=rtn.replace("},","}");
	return rtns;
};

vars.put("jsonString", genJsons());

 3.使用json数据请求

 

转载于:https://www.cnblogs.com/sunny-sl/p/8044237.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值