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数据请求