Passing request body from json file to artillery api tests. #2638
Replies: 3 comments 12 replies
-
Hi @BhavnaSoni1991 👋 IMO the easiest way to do it is to use a custom javascript function, where you can require the JSON file and then set the body directly to it:
const myJson = require('./path-to-json');
function setJSONBody(requestParams, context, ee, next) {
requestParams.body = JSON.stringify(myJson);
return next();
}
module.exports = { setJSONBody }; Then, you can call that in a config:
...
processor: './processor.js'
scenarios:
- flow:
- post:
url: '/'
beforeRequest: "setJSONBody" |
Beta Was this translation helpful? Give feedback.
-
Hi @bernardobridge my script ran file on local using the code snippet above but in the gitlab pipeline I am getting following "MODULE_NOT_FOUND" error when trying to run on aws fargate. |
Beta Was this translation helpful? Give feedback.
-
hi @bernardobridge below is the full file structure of my scenario file(test3.yml), config is same yml file (test3.yml), processor (helper.js), json (test3.json) file. |
Beta Was this translation helpful? Give feedback.
-
I want to add performance tests for api having quite complex request payload and hence want to pass them through json file. Does artillery support reading request payload from json file? In the examples I could see request payload values are directly passed in yml file and not read from any file.
Beta Was this translation helpful? Give feedback.
All reactions