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
Debug output in tests
提问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()
似乎正在工作,但我想将我的信息输出到我的断言所在的同一面板中(以便于关联):
回答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
启用它
- Type
chrome://flags
inside your Chrome URL window - Search for "Debugging for packed apps" setting
- Enablethe setting
- Restart Chrome
- 输入
chrome://flags
您的Chrome URL窗口内 - 搜索“调试打包应用程序”设置
- 启用设置
- 重启 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/#apps
and then click "inspect"
您也可以转到
chrome://inspect/#apps
然后单击“检查”
回答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,
反而,
- Head to View in the application menu, and click on "Show DevTools".
- In the DevTools window, clicking on the top level Console tab should show the app's debug logs.
- 前往应用程序菜单中的查看,然后单击“显示 DevTools”。
- 在 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 :
回复 :