Reputation: 264
I am testing the api where i have to sent the post request and as request body I am using form-data where i have 03 text field and one image , locally the tests works but when i tried to run via newman run command as a part of gitlab CI/CD it never found the file and i got timeout error here is the code snippet of my gitlab-ci file
newman run Postman_Collections/Media.json -e envtest.json --global-var "file=Images/Test.jpg"
Here is project structure in gitlab repository
i have also save the relative path inside the media.json collection by editing it vscode json editor , here how it looks like
"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": []
}
Am i missing something or messing up with the path inside the collection.json file or with newman run command.
Upvotes: 1
Views: 314
Reputation: 264
I have found the workaround , if any one in future looks for similar thing , can follow following steps Upload your test file in postman go to postman => body tab then select form-data and upload the file export the specific collection Open the collection.json file in any editior (for e.g. VS-Code) in the body array add src if not existed and then provide the relavent path of the image and removed the local path Make sure that your test file should exist in the same directory where collection is in my case i have something like this Project/Collection.json Project/Images/Test.jpg
this is how I passed the path "src" : "./Images/Test.jpg"
then newman will locate the file and it will work when gitlab-ci pipeline starts
Upvotes: 1