Javascript 测试中的调试输出

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/31157675/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 06:19:25  来源:igfitidea点击:

Debug output in tests

javascripttestingloggingpostman

提问by UserControl

How do I output some information in Postman tests?

如何在 Postman 测试中输出一些信息?

console.log(tv4.error);
tests["Valid Data1"] = tv4.validate(data1, schema);

console.log()seems to be working but I want to output my info into the same panel where my assertions go (for easier correlation):

console.log()似乎正在工作,但我想将我的信息输出到我的断言所在的同一面板中(以便于关联):

enter image description here

在此处输入图片说明

回答by Veener

Just make a fake test that passes:

只需做一个通过的假测试:

var jsonData = JSON.parse(responseBody);
tests["id = " + jsonData.id] = true;              // debug message
tests["name = " + jsonData.name] = true;          // debug message

回答by cilerler

Reference for the people who just want to use Chrome's Developer Tools (which will let you see console output and give you many more features)

给只想使用 Chrome 开发者工具的人参考(它会让你看到控制台输出并为你提供更多功能)

To enable it

启用它

  1. Type chrome://flagsinside your Chrome URL window
  2. Search for "Debugging for packed apps" setting
  3. Enablethe setting
  4. Restart Chrome
  1. 输入chrome://flags您的Chrome URL窗口内
  2. 搜索“调试打包应用程序”设置
  3. 启用设置
  4. 重启 Chrome

You can access the Developer Tools window by right clicking anywhere inside Postman and selecting "inspect element".

您可以通过右键单击 Postman 内的任意位置并选择“检查元素”来访问“开发人员工具”窗口。

You can also go to chrome://inspect/#appsand then click "inspect"

您也可以转到chrome://inspect/#apps然后单击“检查

Reference

参考

回答by Swagin9

I used this, which isn't the prettiest, but it works for what I needed.

我使用了这个,这不是最漂亮的,但它适用于我需要的东西。

tests["your test name here " + data.data.length] = data.data.length > 100;

回答by Patrick

Piggybacking on the other answers, just define a function in your Postman test code

捎带其他答案,只需在 Postman 测试代码中定义一个函数

var print = function(s){
  tests[s] = true;  
};

then consume it like

然后消费它就像

print("current value of x: " + x);

回答by bdphilly

Similar to a previous answer regarding an alternate option: using dev tools. However, if you are using the native app, right clicking to get the dev tools won't work.

类似于先前关于替代选项的答案:使用开发工具。但是,如果您使用的是本机应用程序,则无法右键单击以获取开发工具。

Instead,

反而,

  1. Head to View in the application menu, and click on "Show DevTools".
  2. In the DevTools window, clicking on the top level Console tab should show the app's debug logs.
  1. 前往应用程序菜单中的查看,然后单击“显示 DevTools”。
  2. 在 DevTools 窗口中,单击顶级控制台选项卡应显示应用程序的调试日志。

Reference: https://learning.getpostman.com/docs/postman/collection_runs/debugging_a_collection_run

参考:https: //learning.getpostman.com/docs/postman/collection_runs/debugging_a_collection_run

回答by Daniel Hornik

Now You have got sth called "Postman Console" To run it please type CTRL + ALT + C For mor info see here: https://blog.getpostman.com/2016/08/26/the-postman-console/

现在你有一个叫做“邮递员控制台”的东西要运行它,请输入 CTRL + ALT + C 有关更多信息,请参见此处:https: //blog.getpostman.com/2016/08/26/the-postman-console/

回答by Pramod Dutta

One of the way is use the tests[""+value].

一种方法是使用测试 [""+value]。

e.g

例如

http://api.openweathermap.org/data/2.5/weather?q=London,uk&appid=Your_API_Key.

http://api.openweathermap.org/data/2.5/weather?q=London,uk&appid=Your_API_Key

Response :

回复 :

Blockquote

块引用