[英]I am getting script Error when try to compare expected value with incorrect value. if I compare it with correct value it will give correct result data
I am getting test script Error (not getting the test results) (see 1st image) when try to compare expected value with incorrect value.尝试将预期值与不正确的值进行比较时,我收到测试脚本错误(未获得测试结果)(参见第一张图片)。 if I compare it with correct value it will give correct result data (see the 2nd image)如果我将它与正确的值进行比较,它将给出正确的结果数据(参见第二张图片)
error code :错误代码 :
pm.test("Row : " + i + " - " + dataArr[1] + " : Verify symbol Instrument type with DB", function () {
var insTypeRes = dataArr[2];
var intInsType = parseInt(insTypeRes);
console.log("insType " + intInsType);
pm.sendRequest("http://192.168.xx.xxx:8080/ords/unidata/symbol/symbol/" + dataArr[1], function (err, response) {
var resBoday = response.json()
var insTypeDB = resBoday.items[0].instrument_type_id;
var intInsTypeDB = parseInt(insTypeDB);
console.log("insTypeDB " + intInsTypeDB);
pm.expect(intInsTypeDB).is.to.equals(61);
});
});
The documentation for pm.test
suggests that testing an asynchronous result should call a done
callback passed to the test function as an argument, and a call to done
be made after the assertion. pm.test
的文档建议测试异步结果应该调用作为参数传递给测试函数的done
回调,并在断言之后调用done
。
However , while you are welcome to try it, the chance of this being able to include a failed test in Test Results
is potentially non-existent: if the expect
assertion throws, a done()
call placed after it never gets executed.但是,虽然欢迎您尝试,但在Test Results
包含失败测试的可能性可能不存在:如果expect
断言抛出,则在它永远不会执行之后放置done()
调用。
This postman blog article contains an example headed这篇邮递员博客文章包含一个标题为
// example containing a test ** under the Tests tab only
which suggests that to log the failure under Test Results, change the expect
assertion in the request callback function,这表明要在测试结果下记录失败,请更改请求回调函数中的expect
断言,
pm.expect(intInsTypeDB).is.to.equals(61);
into a pm.test
definition:进入pm.test
定义:
pm.test("Row : " + i + " - " + dataArr[1] + " : Instrument type is valid", function() {
pm.expect(intInsTypeDB).is.to.equals(61);
});
If you try this, make sure that the loop variable i
is declared with let
and not var
so that the name string passed to pm.test
contains the correct value of i
.如果您尝试这样做,请确保使用let
而不是var
声明循环变量i
,以便传递给pm.test
的名称字符串包含正确的i
值。
To answer the question in comments, at the moment the test function returns without throwing an error (the call back is called after the network request has been performed), so the catch clause of a try/catch
block the runner places around the test function call will not be triggered.为了回答评论中的问题,此时测试函数返回而不会抛出错误(在执行网络请求后调用回调),因此运行程序放置在测试函数周围的try/catch
块的 catch 子句不会触发调用。
Postman appears to have added a global error
handler to catch and report assertion errors that were not otherwise caught. Postman 似乎添加了一个全局error
处理程序来捕获和报告没有被捕获的断言错误。 Hence the因此
There was an error in evaluating the test script: ...评估测试脚本时出错:...
error message appears on the console and not in Test Results because the test function that the (anonymous) function raising the error is nested within is unknown.错误消息出现在控制台上,而不是在测试结果中,因为引发错误的(匿名)函数嵌套在其中的测试函数是未知的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.