【发布时间】:2019-11-12 23:19:09
【问题描述】:
我正在尝试在我的邮递员回复中添加一个断言- 添加了 TaskId 的新任务项:ce0bb7ee-b31d-47c7-afb8-d65c371870d9 其中有一个动态 guid 值。动态子字符串的断言失败。请指教
var responseText = pm.response.text();
ResponseTextContains = (text) => {
pm.test("Body contains " + text , function () {
pm.expect(responseText).to.include(text);
});
};
ResponseTextContains("new task item added with TaskId : ce0bb7ee-b31d-47c7-afb8-d65c371870d9");
考虑到动态子字符串值,我希望我的断言应该通过
【问题讨论】:
-
您能添加一个示例响应吗?是 JSON 还是明文?
-
你为什么不直接使用
pm.expect(responseText).to.include('new task...TaskId :');?您需要验证 id 格式吗? (我猜是uuid) -
感谢您的回复,我不需要验证 id 格式只是想检查 uuid 是否存在。我的回复是纯文本,例如 - 添加了 TaskId 的新任务项:7a863af5-766b-4f0d-b873-aeffab2ba2f9
标签: javascript postman assertion