邮递员控制台输出可点击的 URL



如何在 Postman 控制台(本机应用程序(中从测试脚本中输出可点击的 URL?

就像启动邮递员控制台时的"https://go.pstmn.io/postman-jobs"一样。

对于 API 调用序列,您可能正在使用运行器。 因此,您可以将经度值存储在变量中,并将它们传递给谷歌地图的其他URL。

请求 1:需要在环境中存储经度值

let resp = pm.response.json();
pm.environment.set("latitude",resp.lat); 
pm.environment.set("longitude",resp.longitude);
postman.setNextRequest("Googlemaps"); // need to pass request name(used in postman) which need to be called 

请求 2:在运行器中,对于第二个请求,在测试中添加以下行以停止测试:

postman.setNextRequest(null);

这很老了,但我找到了一种笨拙的方法。

步骤 0.拥有您的网址

有很多方法使用 Postman 中的前/后脚本功能从某些 API 输出生成它

第 1 步。设置在本地主机上运行的简单 API 启动浏览器

对我来说,我使用express和node来做到这一点,类似于

const express = require('express');
const app = express();
const open = require('open');
const bodyParser = require('body-parser');
const port = 1;
app.use(bodyParser.urlencoded({ extended: true }));
app.get('/open-url', (req, res) => {
open(req.body.q);
res.send('Hello World!');
});
app.listen(port, () => {
console.log(`Example app listening at http://localhost:${port}`);
});

在 http://localhost:1 上运行。

第 2 步。在邮递员中创建 GET 请求

一个简单的例子

curl --location --request GET 'http://localhost:1/open-url' 
--header 'Content-Type: application/x-www-form-urlencoded' 
--data-urlencode 'q=http://google.com'

最新更新