我使用的是开放式 API.
I'm using an open API.
但我只使用了 API 提供的响应中的一小部分数据.当我使用具有不同参数的 API 进行测试以查看响应时.
But I am only using a small bit of data from the response the API provides. And as I'm testing using the API with different parameters to see the responses.
我不想在每次发送请求时看到整个 API 响应,我只想看到我感兴趣的数据.
I don't want to see the entire API response every time I send the request, I only want to see the data that I'm interested in.
例如:
响应有 3 个对象.Status、Features 和 Data.但是我只对 Data 对象感兴趣,我只想在发出请求时看到 Data 对象
The response has 3 objects. Status, Features and Data. But I'm only interested in the Data object, I only want to see the Data object when making the request
有没有办法可以使用请求的实际响应打印不同的响应?
Is there a way I can print a different Response, using the actual response of the Request?
运行测试以验证数据,并且使用 Pre-Request 脚本在请求之前做一些事情,但我没有发现任何改变响应形式的东西.
Tests are run to validate data, and Pre-Request scripts are used to do something before the request, but I haven't found anything that changes the form of the Response.
推荐答案没有修改 body 的选项,但你可以使用 postman 中惊人的可视化功能:
There is no option to modify body but you can use the amazing visualizer feature in postman:
例如:
设置网址和方法:
GET : reqres.in/api/users?page=2在测试脚本中添加以下代码:
template = `<table bgcolor="#FFFFFF"> <tr> <th>Name</th> <th>Email</th> </tr> {{#each response}} <tr> <td>{{first_name}}</td> <td>{{email}}</td> </tr> {{/each}} </table> `; // Set visualizer pm.visualizer.set(template, { // Pass the response body parsed as JSON as `data` response: pm.response.json().data });现在点击可视化:
您可以看到可视化将只显示名字和电子邮件作为表格.
You can see the visualize will show only first_name and email as a table .
你可以在你的情况下使用相同的逻辑
You can use same logic in your case
如果您想将其打印为 json 本身,请在测试脚本中使用以下代码:
template = ` <pre><code>{{response}}</code></pre> `; console.log( JSON.stringify(pm.response.json().data, undefined, 2)) // Set visualizer pm.visualizer.set(template, { // Pass the response body parsed as JSON as `data` response: JSON.stringify(pm.response.json().data, undefined, 2) });输出:
更多推荐
在 PostMan 中更改响应
发布评论