【问题标题】:Is there to run only part of requests in Postman?在 Postman 中是否只运行部分请求?
【发布时间】:2021-01-26 13:50:08
【问题描述】:

我们在 Postman 中编写了许多 API 级别的自动化测试作为请求集合。

我们有一个脚本可以自动运行所有集合。

有没有办法只标记/运行请求的子集,例如带有一些标签,例如作为烟雾套件,无需将请求复制到新集合并显式运行(因为这需要在 2 个地方维护相同的测试...)?

可能存在跳过请求的标签、组或某些脚本设置环境变量...

【问题讨论】:

  • 必须有比创建大量冗余的文件夹更好的方法来做到这一点。也许version control?但确实感觉应该有一个功能,可以根据一些环境变量禁用查询,过滤查询以在 Runner 中运行或类似的东西。
  • 只需按 ctrol+o 导入并选择链接,然后使用该链接

标签: postman postman-collection-runner


【解决方案1】:

你可以创建文件夹并组织测试

  1. smoke_and_regression
  2. smoke_only 等

使用 newman 作为命令行工具时,您可以使用 --folder 参数指定运行哪个文件夹

您还可以使用 postman.setNextRequest 控制执行流程。

您也可以将 newman 作为 npm 模块运行。

您只需要编写一个逻辑来读取集合文件并获取所有包含“烟雾”的文件夹名称,例如并将其作为数组传递

const newman = require('newman'); // require newman in your project

 

// call newman.run to pass `options` object and wait for callback
newman.run({
    collection: require('./sample-collection.json'),
    reporters: 'cli',
    folder: folders
}, function (err) {
    if (err) { throw err; }
    console.log('collection run complete!');
});

只需更新 cmets:

在新旧 UI 中,您可以选择在 collection runner 中执行哪个文件夹

【讨论】:

  • @Rob 在以前的版本中也有 :)
  • 在集合运行器中,您可以查看和取消选择要运行的请求或集合
  • 是的,您也可以在旧应用程序的邮递员集合运行器 ui 中选择文件夹
  • 您可以在dl.pstmn.io/download/version/7.36.5/osx64下载以前的版本
  • 如果有帮助,请接受或投票
【解决方案2】:

获取集合中的所有请求:

您还可以使用以下方法获取有关集合中所有请求的信息:

https://api.getpostman.com/collections/{{collection_UUID}}

获取 uuid 和 api 密钥 goto :

https://app.getpostman.com

现在用于生成 api 密钥 >

转到帐户设置> api key 并生成api key。

获取集合 uuid 转到特定工作区和集合并从 url 复制 uuid 部分:

现在在您的收藏中

将所有请求重命名为:

get user details [Regression][Smoke][Somethingelse]
get account details [Regression]

然后创建一个名为 initial request 的新请求,并将其作为您集合中的第一个请求:

网址: https://api.getpostman.com/collections/8xxxxtheuuidyoucopied

授权: apikey-header : key: X-Api-Key and value: yourapikey

测试脚本

pm.environment.unset("requestToRun")
reqeustlist = pm.response.json().collection.item.map((a) => a.name)
requestToRun = reqeustlist.filter((a) => a.includes(pm.environment.get("tag")))
let val = requestToRun.pop()
pm.environment.set("requestToRun", requestToRun)
val ? postman.setNextRequest(val) : postman.setNextRequest(null)

现在将环境变量设置为您要查找的变量,例如:运行包含文本“回归”的脚本,然后设置pm.environment.set("tag","Regression")

现在在您的收藏前请求中添加:

if (pm.info.requestName !== "initial request") {
    let requestToRun = pm.environment.get("requestToRun")
    let val = requestToRun.pop()
    pm.environment.set("requestToRun", requestToRun)
    val ? postman.setNextRequest(val) : postman.setNextRequest(null)
}

输出:

示例集合:

https://www.getpostman.com/collections/73e771fe61f7781f8598

只运行名称中包含“复制”的请求

【讨论】:

    猜你喜欢
    • 2021-11-16
    • 1970-01-01
    • 2019-07-29
    • 2021-03-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-23
    • 1970-01-01
    • 2021-11-28
    相关资源
    最近更新 更多