【问题标题】:Postman Console Output Clickable URLPostman 控制台输出可点击 URL
【发布时间】:2018-12-13 01:07:37
【问题描述】:

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

就像启动 Postman 控制台时的“https://go.pstmn.io/postman-jobs”一样。

【问题讨论】:

  • 请问您为什么需要这样做?
  • 我想做一个 API 调用序列的演示。最后一次调用返回用作谷歌地图输入的纬度/经度数据。我没有找到直接启动此 URL 的方法。

标签: postman


【解决方案1】:

这已经很老了,但我找到了一个 hacky 方法来做到这一点。

第 0 步。拥有您的网址

有很多方法可以使用 Postman 中的 pre/post 脚本功能从一些 API 输出生成它

步骤 1. 设置一个在 localhost 上运行的简单 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. 在 Postman 中创建 GET 请求

一个简单的例子

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

【讨论】:

    【解决方案2】:

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

    请求 1:您需要在环境中存储 lat-long 的值

           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);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-11-22
      • 2013-02-11
      • 2022-08-12
      • 2022-01-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-11-16
      相关资源
      最近更新 更多