How can I run a Node-js script in Artillery.i.o without including it in Load test scenario

岁酱吖の 提交于 2019-12-08 00:57:17

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/42196637/how-can-i-run-a-node-js-script-in-artillery-i-o-without-including-it-in-load-tes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!