简体   繁体   English

尝试将预期值与错误值进行比较时出现脚本错误。 如果我将它与正确的值进行比较,它将给出正确的结果数据

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

相关问题 如何将数据库值与 javascript 值进行比较。? - How to compare database value with javascript value.? 访问 Promise.allSettled 响应属性值。 为什么我会收到错误消息? - Accessing Promise.allSettled response property value. Why am I getting an error? 即使数据值不正确,也无法显示正确的按钮 - can't show correct button even when data value is incorrect 我正在使用javascript计算页面加载时间。 但不幸的是,我得到的是负值。 - I am calculating page load time using javascript. But unfortunately I am getting it in negative value. 当我将我的输入值与 csv 列进行比较时,为什么会得到未定义的值 - Why getting Undefined value when i compare my input value to csv column 尝试从标签获取数据时获取未定义的值 - Getting an undefined value when I try to get data from a label 我如何比较价值 - How do I compare the value 当我拥有键和值时,为什么会出现错误? - Why am I getting the error when I have the key and value? 我从 Api 获取数据,但是当我尝试使用 useState 设置值时,它给了我一个空的 object - I get data from Api but when I try to set the value with useState it give me an empty object 如何在数组中存储单选按钮值并比较以得到正确答案? - How to store radio button value in array and compare to correct answer?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM