0

After successfully extracting username and password from a csv as shown in the documentation, I noticed that my username was in the following format: "\ntomer@mail.com". How can I erase the "\n" char in artillery?


P.S.

The way to check your HTTP request is (I was unable to find documentation for this):

In cmd do the following command:

set DEBUG=http,http:capture,http:response

Afterwards, every regular artillery request will give you a http debug mode as following:

 http request: {
  "url": "https://host.com/api/user/login",
  "method": "POST",
  "headers": {
    "user-agent": "Artillery (https://artillery.io)"
  },
  "json": {
   "email": "\ntomer@mail.com",
   "password":"9526e7bb980ba35a1788d46d4a2aaaaa3d941d2efc8a4fcb1402d1"
    }
  }
}
Tomer
  • 531
  • 7
  • 19

1 Answers1

1

I solved the problem by using JS as follows (solution is based on this)

In the config section of the yml I set that the JS file to be called would be login.js by adding the following line:

processor: "./js/login.js"

When sending my login request I called the "setJSONBody" function as following:

- post:
    url: "https://dev-api.host.com/api/user/login"
    beforeRequest: "setJSONBody" 
    json:
        email: "{{ user }}"
        password: "{{ password }}"

Here is my login.js file:

  //
  // my-functions.js
  //
  module.exports = {
    setJSONBody: setJSONBody
  }

  function setJSONBody(requestParams, context, ee, next) {

    context.vars.user = context.vars.user.replace('\n',''); //erases from user name any \n char

    return next(); // MUST be called for the scenario to continue
  }
Tomer
  • 531
  • 7
  • 19