GT postman脚本
body
{"SysHead":{{head}},"Body":{{body}}}
prerequest-预请求脚本
pm.environment.set("head",JSON.stringify(pm.iterationData.get("SysHead")))
pm.environment.set("body",JSON.stringify(pm.iterationData.get("Body")))
post response - 测试
// 获取响应体
const response = pm.response.json();
// 检查StatusNo是否为"01"
const isTransactionSuccess = response.SysHead.StatusNo === "01";
// 检查StatusDec是否包含中文“重复”字样
const containsDuplicate = response.SysHead.StatusDec.indexOf("重复") !== -1;
// 根据交易是否成功和是否包含“重复”字样,设置测试结果
if (isTransactionSuccess && !containsDuplicate) {
pm.test("交易成功且不包含'重复'", function () {
pm.expect(true).to.be.true;
});
} else if (containsDuplicate) {
pm.test("交易包含'重复'情况", function () {
pm.expect(containsDuplicate).to.be.true;
// 使用pm.itest来标记这个测试用例为跳过
pm.itest.Skipped = true;
});
} else {
pm.test("交易失败", function () {
pm.expect(isTransactionSuccess).to.be.false;
});
}