简体   繁体   English

如何获取 Postman 中的测试状态(即通过、失败或错误)?

[英]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.

相关问题 如何将实际对象(即对对象的引用)传递给指令? - How to pass an actual object (i.e. reference to an object) to a directive? 如何获得屏幕的物理尺寸(即英寸)? - How to get screen's physical size (i.e. in inches)? 如何通过这个 postman 脚本测试? - how to pass this postman script test? 如何将复杂的样式(即样式表)传递给React组件作为道具? - How do I pass complex styles (i.e. stylesheets) to React components as props? 如何将参数传递给内置函数的回调? (即HTMLCanvasElement.toBlob) - How to pass a parameter to a built-in function's callback? (i.e. HTMLCanvasElement.toBlob) 如何通过 JavaScript - postMessage() 中的 web worker 传递可转移对象数组,即缓冲区以及不可转移的 object,即 json obj? - How to pass array of transferable objects i.e. buffer along with non transferable object i.e. json obj via web worker in JavaScript - postMessage()? 在angularJS路由中传递2个不同的参数,即Id和Name - Pass 2 different parameter i.e. Id and Name in angularJS Routing 无法修改Controls集合,因为控件包含代码块(即&lt;%...%&gt;)。 无法解决此错误 - The Controls collection cannot be modified because the control contains code blocks (i.e. <% … %>). cant get this error out 是否可以使用 POSTMAN 发布多个数据,即 object 的数组 - Is it possible to post multiple data i.e., array of object using POSTMAN 如何在没有webserver-stuff(即AJAX)的情况下获取外部JavaScript的文本 - How to get the text of a external JavaScript without webserver-stuff (i.e. AJAX)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM