[英]How to get the status of test(i.e. pass or fail or error) in Postman?
Here is my test case in postman这是我在 postman 中的测试用例
pm.test("verify the JSON object keys for machines - ", function() {
if (Object.keys(data).length === 0) {
pm.expect(Object.keys(data).length).to.eq(0);
}
}
Now if status of this test is PASS
then I don't want to execute next test case but if status is FAIL
then next test case should get executed Next test case is -现在如果这个测试的状态是
PASS
那么我不想执行下一个测试用例但是如果状态是FAIL
那么下一个测试用例应该被执行下一个测试用例是 -
pm.test("verify the JSON object keys for machines- ", function() {
pm.expect(data[1]).to.have.property('timeStamp');
}
Perhaps this can be achieved by programmatically skip the tests.也许这可以通过以编程方式跳过测试来实现。 Here is the syntax
这是语法
(condition ? skip : run)('name of your test', () => {
});
Take one variable, update it if the result of the first test is passed取一个变量,如果第一次测试的结果通过则更新它
var skipTest = false;
pm.test("verify the JSON object keys for machines - ", function() {
if (Object.keys(data).length === 0) {
pm.expect(Object.keys(data).length).to.eq(0);
skipTest = true // if the testcase is failed, this won't be updated
}
}
(skipTest ? pm.test.skip : pm.test)("verify timeStamp keys for machines-", () => {
pm.expect(data[1]).to.have.property('timeStamp');
});
Result Skip结果跳过
Result Without Skip结果不跳过
Logically, you need the "OR" function, but there is no such one in the postman.从逻辑上讲,您需要“或”function,但在 postman 中没有这样的。 What I would suggest is to get true/false result end check it with the postman.
我建议使用 postman 获得真/假结果。
pm.test("verify the JSON object keys for machines - ", function() { const result = Object.keys(data).length === 0 || // true if there are no properties in the data object 'timeStamp' in data; // or true if there is timeStamp property in the data object pm.expect(lengthEqualZero || hasPropertyTimeStamp).to.be.true; }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.