artilleryio / artillery-core

artillery-core - deprecated
Mozilla Public License 2.0
29 stars 104 forks source link

beforeReqeust's requestParams can't be customized. #187

Open outsideris opened 7 years ago

outsideris commented 7 years ago
- post:
    url: '/login'
    beforeRequest: 'setDeviceAsJson'
    json:
      grant_type: 'password'
      email: '{{ username }}'
      password: '{{ password }}'
      device: '{{ device }}'

In here, device is JSON, but the request stringifies it. So, I want to customize device in beforeRequest hook.

As the document, requestParams object is for it.

requestParams is an object given to the Request library. Use this parameter to customize what is sent in the request (headers, body, cookies etc)

// process.js
module.exports = {
  setDeviceAsJson: (requestParams, context, ee, next) => {
    requestParams.json.device = JSON.parse(context.vars.device);
    return next();
  },
};

However, reqeust's json wasn't changed, even if requestParams was changed.

In here, requestParams is overwritten after running beforeRequest hook. This change was introduced in this commit, but I can't understand what your intention is.

requestParams looks useless in the hook.

outsideris commented 7 years ago

If I define the customized value in context.vars, I can change the request's json. I think the document should be updated. But I wanna use the device as JSON rather than stringified one.