Routed load testing in routes in phoenix

I am trying to do load testing for routes requiring login.

I previously used https://artillery.io/docs/index.html for worked out routes that worked fine. To enter the routes, I tried calling beforeRequest using the function to set the headers and request body.

config: target: "https://www.mywebsite.com/" phases: - duration: 60 arrivalRate: 50 processor: "test.js" scenarios: - flow: - post: url: "/login" beforeRequest: "setReqBody"

and my beforeRequest looked like this:

function setReqBody(requestParams, context, ee, next) { requestParams.body = {'email': ' user@mail.com ', 'password': 'password', '_csrf_token': window.csrfToken} return next(); }

I get a window undefined error message.

I looked around to see if there was anything else I could use to test the phoenix at boot, but didn't have much luck. Is there any other way to register and verify these routes? Or other dependencies / libraries that I can use for this?

+5
source share
2 answers

The problem is that window not defined in the context in which the beforeRequest function beforeRequest (since the code is not running in the browser).

If the CSRF token is included somewhere in the DOM / HTML on the login page, you can grab it first and then include it in the POST request. For example, if there was a hidden input in the login form containing a CSRF token with name attribute = csrfToken :

 scenarios: - flow: # Get the login page and grab the CSRF token - get: url: "/login" capture: selector: "input[name='csrf_token']" attr: "value" as: "csrfToken" # Useful for debugging: check that we used the right selector: - log: "Extracted CSRF token: {{ csrfToken }}" # Now send a login request: - post: url: "/login" form: email: " user@mail.com " password: "password123" _csrf_token: "{{ csrfToken }}" # The session cookie will be remembered and reused automatically by # Artillery from this point onwards. 
+2
source

Consider using Apache JMeter :

For more information, see Checking the REST API - how to do it correctly .

+1
source

Source: https://habr.com/ru/post/1268669/


All Articles