我正在测试API,我必须在其中发送帖子请求,并且作为请求正文,我正在使用表单数据,其中我有03文本字段和一张图像,本地测试有效,但是当我尝试通过newman run命令运行时gitlab CI/CD 的一部分它从未找到该文件,并且出现超时错误 这是我的 gitlab-ci 文件的代码片段
newman run Postman_Collections/Media.json -e envtest.json --global-var "file=Images/Test.jpg"
这是 gitlab 存储库中的项目结构
我还通过使用 vscode json 编辑器编辑它来保存 media.json 集合中的相对路径,如下所示
"info": {
"_postman_id": "d1c41d43-16c7-40b0-bdec-9d41258bd9ef",
"name": "Media",
"item": [
{
"name": "Test",
"item": [
{
"name": "Create media file",
"event": [
{
"listen": "test",
"script": {
"exec": [
"\"Test 01\"\r",
"pm.test(\"Validate status code.\", function () {\r",
" pm.response.to.have.status(201);\r",
"});"
],
"type": "text/javascript",
"packages": {}
}
},
{
"listen": "prerequest",
"script": {
"exec": [
""
],
"type": "text/javascript",
"packages": {}
}
}
],
"protocolProfileBehavior": {
"disabledSystemHeaders": {}
},
"request": {
"method": "POST",
"header": [
{
"key": "Authorization",
"value": "ApiKey {{testkey}}",
"type": "text"
}
],
"body": {
"mode": "formdata",
"formdata": [
{
"key": "test",
"value": "abc",
"type": "text"
},
{
"key": "documenttype",
"value": "test123",
"type": "text"
},
{
"key": "iteminfo",
"value": "11243200484648",
"type": "text"
},
{
"key": "file",
"type": "file",
"src": "Images/Test.jpg"
}
]
},
"url": {
"raw": "localhost:1234/TestMedia",
"protocol": "https",
"path": [
"api",
"MediaAssets"
]
}
},
"response": []
}
我是否遗漏了某些内容或弄乱了 collection.json 文件内的路径或 newman run 命令。
我已经找到了解决方法,如果将来有人寻找类似的东西,可以按照以下步骤在邮递员中上传测试文件,转到邮递员=>正文选项卡,然后选择表单数据并上传文件导出特定集合打开集合任何编辑器(例如 VS-Code)中的 .json 文件在主体数组中添加 src(如果不存在),然后提供图像的相关路径并删除本地路径确保您的测试文件应存在于集合所在的同一目录中就我而言,我有这样的事情 项目/Collection.json 项目/图像/测试.jpg
这就是我走过的路 “src”:“./Images/Test.jpg”
然后 newman 将找到该文件,并且它将在 gitlab-ci 管道启动时工作