admin管理员组文章数量:1393049
Here is my test case in 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 -
pm.test("verify the JSON object keys for machines- ", function() {
pm.expect(data[1]).to.have.property('timeStamp');
}
Here is my test case in 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 -
pm.test("verify the JSON object keys for machines- ", function() {
pm.expect(data[1]).to.have.property('timeStamp');
}
Share
Improve this question
asked Nov 9, 2019 at 13:23
DevDev
2,8112 gold badges24 silver badges37 bronze badges
2 Answers
Reset to default 4 +50Perhaps 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. What I would suggest is to get true/false result end check it with the 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;
}
本文标签: javascriptHow to get the status of test(ie pass or fail or error) in PostmanStack Overflow
版权声明:本文标题:javascript - How to get the status of test(i.e. pass or fail or error) in Postman? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744593644a2614645.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论