2

I am to load test a scenario where user adds a contact in his addressbook. To do this user must first Log-In to his account.
I have a Nodejs script 'AutoLogin.js' that performs Log-In for the user and a json file 'contact.json' which has necessary configuration and POST request parameters to add contact in addressbook.
Artillery runs 'contact.json' file.

 {
  "config": {
    "target": "target url",
    "https": {
        "tls": {
          "rejectunauthorized": false
        }
    },
    "phases": [
      {
        "duration": 10,
        "arrivalRate": 2
      }
    ]
  },
  "scenarios": [
    {
      "flow": [
        {
          "post": {
            "url": "/addContact",
            "contactInfo": {
              "Name": "Davion",
              "Mobile": "9289543654",
              "Email": "Davion@gmail.com"
            }
          }
        }
      ]
    }
  ]
}

Given code sends 2 Post request/sec i.e simulating 20 users adding a contact to addressbook over a duration of 10 seconds.
I need to perform Log-In before this code runs as adding a contact without Log-In is not possible.
Plus I don't want Log-In process to be included in load test. Is there a way I Can run my 'AutoLogin.js' script within 'contact.json' file without including it in load test and then running 'contact.json' using Artillery?

Pawan Juyal
  • 251
  • 1
  • 5
  • 14

1 Answers1

0

If you need to login before every single request:

  1. In the config section of the YAML file, add a processor line with your custom JS specified. Note, your JS is expected to be a standard Node.js module:
"config": {
  "processor": "AutoLogin.js"
}
  1. In the post action of your flow, add a line for the beforeRequest hook:
"post": {
  "url": "/addContact",
  "beforeRequest": "functionFromAutoLogin", 
  "contactInfo": {
    "Name": "Davion",
    "Mobile": "9289543654",
    "Email": "Davion@gmail.com"
  }
}

From: https://artillery.io/docs/http-reference/#advanced-writing-custom-logic-in-javascript

See also https://artillery.io/docs/script-reference/#payload-files for using a CSV for the test data.

Mickster37
  • 155
  • 2
  • 10