可以将所有测试和请求的结果导出到文件中,然后导入到Postman中进行进一步分析。使用JSON报告程序和文件名将运行器输出保存到文件中。
我已经尝试过:
newman run "Echo.postman_collection.json" --reporters cli,json --reporter-json-export outputfile.json
Run Code Online (Sandbox Code Playgroud)
但是我没有设法将outputfile.json导入Postman Collection Runner。我总是收到以下错误消息:
Runner.js:81831未捕获的数据错误:无法在“ IDBObjectStore”上执行“ put”:评估对象存储的键路径未产生值。
我究竟做错了什么?
这是Newman创建的outputfile.json。它实际上具有与Postman Collection Runner中导出的测试运行不同的结构:
{
"collection": {
"info": {
"id": "ef224090-5564-258f-6ca5-68bd578a6c8d",
"name": "Echo",
"schema": "https://schema.getpostman.com/json/collection/v2.0.0/collection.json"
},
"event": [],
"variable": [],
"item": [
{
"id": "2cf3e4a4-eb9e-4622-bade-d0536161c97d",
"name": "Delay",
"request": {
"url": "https://postman-echo.com/delay/3",
"method": "GET",
"body": {
"mode": "raw",
"raw": ""
},
"description": {
"content": "",
"type": "text/plain"
}
},
"response": [],
"event": [
{
"listen": "test",
"script": {
"type": "text/javascript",
"exec": …Run Code Online (Sandbox Code Playgroud) 我有以下字符串并想提取代码的值。我使用了 split 函数,但它在 postman 中运行良好,但是当我在 newman 中执行相同的函数时,它会出错。
我想提取代码的值。在这种情况下是
EgxIZAAU3uHVt20pc9qqpv-xNcAWxitpB0vgMiulNLG2hkysukmjR04Fxxnuz9Yb
Run Code Online (Sandbox Code Playgroud)
我使用的代码是
var str= pm.response.headers.get('header1');
var str1= str.split('code=', 2)[1];
var code= str1.split('&', 2)[0]; // get the code
Run Code Online (Sandbox Code Playgroud)
它在邮递员中运行良好,但为什么纽曼在这里出错?
我正在使用魅力2.8.1。我已使用 NPM 将其安装到我的 docker 容器中。之后,我运行allure generate test-results命令从 junit xml 生成魅力报告,该报告是使用 newman 工具生成的。
在报告目录中,会出现一个空目录data/attachments和一个data/test-cases包含 junit xml 中所有测试用例的目录。
测试用例 xml 示例:
<?xml version="1.0" encoding="UTF-8"?>
<testsuites name="test-collection-2" tests="1" time="0.463">
<testsuite name="Test succeed request" id="b3ce6542-d493-4206-b67b-e74e4ca58fde" tests="2" failures="0" errors="0" time="0.463">
<testcase name="Status code is 200" time="0.463"/>
<testcase name="Content-Type is present" time="0.463"/>
</testsuite>
</testsuites>
Run Code Online (Sandbox Code Playgroud)
你能帮我解决这个问题吗?
我在命令行中使用以下内容
newman run e_api.json -e ent_env.json --reporters cli,html
Run Code Online (Sandbox Code Playgroud)
但它告诉我 unable to verify the first certificate error
如何忽略 https/ssl 证书错误?
我尝试使用以下命令,但它不起作用。
newman run e_api.json -e ent_env.json --reporters cli,html --ignore-https_proxy
Run Code Online (Sandbox Code Playgroud) 当我在 Newman 和 Postman Runner(主要是 Newman)中运行我的请求集合时,我需要能够在请求之间自动删除 cookie。
我遵循了 Postman 的一个人在这个评论中给出的建议:https ://github.com/postmanlabs/postman-app-support/issues/3312#issuecomment-516965288 。
但它不起作用。
这两个 SO 问题的答案也告诉了执行此操作的相同方法:Postman:如何删除预请求脚本中的 cookie? 以编程方式删除邮递员中的cookie
这是我使用的代码,上面的来源建议将其放置在预请求脚本中:
const jar = pm.cookies.jar();
jar.clear(pm.request.url, function (error) {
console.log("Error: ");
console.log(error);
//handle error
});
Run Code Online (Sandbox Code Playgroud)
[注意:当我运行此代码时,错误被记录为 null]
我已经多次尝试过这段代码,并且对该代码进行了多次不同的修改。我也将域列入白名单。但我总是在请求中得到错误的响应。当我手动清除 cookie(使用 cookie 管理器 UI 对话框)时,请求会给出正确的响应。我需要帮助来确定以编程方式删除 cookie 时可能出现的问题。
我也尝试过查看我要删除的 cookie 是什么:
jar.getAll(pm.request.url, function (error, cookies) {
console.log("Cookies:");
console.log(cookies);
console.log("Error: ");
console.log(error);
});
Run Code Online (Sandbox Code Playgroud)
这里 cookies 是一个空数组。也许这就是问题所在。但这很奇怪,因为当我手动检查 Cookie 管理器时,显示了很多 Cookie。一旦我手动删除 cookie,请求就会返回正确的响应。
我的另一个问题是:上面代码中以“cookies”和“error”作为参数的回调函数的目的是什么。这些函数是每次都会调用还是仅在某些条件下调用?在邮递员文档中找不到回调函数的用途:https://learning.postman.com/docs/postman/sending-api-requests/cookies/
谢谢
我跑
newman run --folder <folder path> -e <environment path>
但它返回一个错误
newman run: error: too few arguments
根据他们的文档,我做对了。
有人遇到过这种情况吗?有没有人解决这个问题?
Newman 帮助指定集合、环境和全局变量可以作为路径或 URL 传递。我可以看到如何从 Postman 获取收藏 URL(通过转到“共享”>“收藏链接”)。
如何在 Postman 中获取 Environment 和 Globals 的 URL,以便将它们传递给 newman?
我有 postman.collection.json 文件,我可以通过 newman 并使用以下命令运行这些集合文件。
newman run test.postman.collection.json -e environment.collection.json -d test.csv
Run Code Online (Sandbox Code Playgroud)
它运行成功并正在返回响应。
我只是想通过使用 Maven 系统获得相同的行为。我需要将它与 pom.xml 集成,以便该文件将运行上述集合。
这可能吗?如果可以这样运行,那么请分享一个示例来展示如何运行。
我有一个 GitLab CI 作业,使用自定义环境运行一系列 Postman 请求。我使用 Newman 与newman-reporter-htmlextra npm 插件一起运行它们以生成测试报告。
该工作如下所示:
postman-tests:
stage: postman-tests
image:
name: wojciechzurek/newman-ci
before_script:
- cd ci/tests/postman
- npm install -g newman-reporter-htmlextra
script:
- newman run Non-regression_tests.postman_collection.json -e Tests.postman_environment.json \
--reporters htmlextra --reporter-htmlextra-export newman-results.html
- ls -la # Check report generation
artifacts:
when: always
paths:
- newman-results.html
allow_failure: true
Run Code Online (Sandbox Code Playgroud)
当我在我的 mac (newman 4.5.0) 上运行 newman 时,请求和相关测试正常运行并生成报告。但是,作业失败并且未生成报告:
$ newman run Non-regression_tests.postman_collection.json -e Tests.postman_environment.json --reporters htmlextra --reporter-htmlextra-export newman-results.html --color
Uploading artifacts...
WARNING: newman-results.html: no matching files
ERROR: …Run Code Online (Sandbox Code Playgroud) 我不是 Node.js 开发人员,但我安装 Newman Postman 只是为了能够对我的 API 进行负载测试。
我想利用下面链接中建议的一个简单想法,从批处理文件并行运行多个 API 请求。来源:https ://community.getpostman.com/t/how-can-i-run-simultaneous-request-parallely/3797/2
由于我缺乏 Node.js 控制台命令的知识,我无法运行脚本文件。使用 Postman 集合列表运行此批处理/文本文件的正确语法是什么?
我试过:
作为上面链接的开发人员建议我创建了 myfile.txt 文件并插入:
newman run c:\path...\collection.json -e c:\path...\staging.json &
newman run c:\path...\collection.json -e c:\path...\staging.json &
newman run c:\path...\collection.json -e c:\path...\staging.json
Run Code Online (Sandbox Code Playgroud)
然后我运行该文件:
newman run c:\path...\myfile.txt
Run Code Online (Sandbox Code Playgroud)
失败。
然后尝试以这种方式运行该文件:
node c:\path...\myfile.txt
Run Code Online (Sandbox Code Playgroud)
没有运气。然后我尝试#!/bin/bash在文件内部添加并以相同的方式运行,但使用 .sh 扩展名。还是没有运气。
如何从此处的文件运行同步 api 调用?