如何使用 Newman API 获取 URL 的整个 html 或 json 响应 [英] how to get whole html or json repsonse of an URL using Newman API

查看:20
本文介绍了如何使用 Newman API 获取 URL 的整个 html 或 json 响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每当我从命令行运行以下内容

Whenever I run following from command line

newman run https://www.getpostman.com/collections/abcd1234

我得到显示失败和执行统计信息的输出.

I get output displaying the statistics of failed and execute.

但我正在寻找执行上述纽曼查询后要在终端上打印的 URL 的完整 HTML 或 JSON 响应.我该如何实现?

But I am looking for the complete HTML or JSON response from the URL to be printed on terminal after executing the above Newman query.How can I achieve this?

推荐答案

我正在使用 newman 进行网络服务和微服务测试.这对我来说很好用.

I am using newman for webservices and microservices testing. This works fine for me.

summary.run.executions[0].response.text().toString()

完成事件后,您应该能够得到响应.

After done event you should be able to get the response.

d 是从 Postman 导出的集合.

d is the collection exported from Postman.

newman.run({
            collection: d,
            // reporters: 'cli',
            iterationCount: 1,
            timeoutRequest: 10000,
            timeoutScript: 5000,
            delayRequest: 0,
            insecure: false, 
        }).on('done', (err, summary) => {
            if (err || summary.error) {
                console.error('\ncollection run encountered an error.');
                reject(summary.error);
            }
            else {
                var xml = summary.run.executions[0].response.text().toString();
                console.log(xml)
            }
        })
    })

这篇关于如何使用 Newman API 获取 URL 的整个 html 或 json 响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆