Load Testing using Artillery.io

109 views Asked by At

I am trying to perform a load test using artillery for a specific user but I am getting 403 when executing the load test.

I have run it in postman using the "userId", all works as I can retrieve the user's info, the API url is good, subscription key good, authorization key good. I am not sure what is the issue in the script in Artillery when performing the load test with the exact credentials. When I am putting the userId in the yml script, in the body, and executing it, I am getting 403 error status in the console output.

config:  
      
      target: 'API endpoint link'
      timeout: 180


      phases:
        - duration: 5
          #arrivalCount: 1
          arrivalRate: 1
          maxArrivalRate: 1
          

      defaults:
        headers:
          AuthorizationSecured: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IlBhbXBlcnMiLCJleHAiOjE3MTUwNTUwOTcsImlhdCI6MTcwNzI5MzY1OX0.wT1QBik1la4Cnx5GQdBh_KBbwjJcURATMdnIgjqY1xA'
          Ocp-Apim-Subscription-Key: '2319f816b2c44bd8abf7598417bf9994'
          Content-Type: 'application/json'
          Cache-Control: 'no-store'
          

      processor: "my-functions.js"
    scenarios:
      - flow:
        - log: "PostUserAction - EntityRetrieve"
        - post:
            url: '/crm'
            beforeRequest: "logBodyReq"
            body: '{"locale": "hr-HR",
              "formType": "EntityRetrieve",
              "Params": {
                "userId" : "auth0|65d5a1fcbb247db30288d6c9",
                
              },
              "getCustomData": false
              }'
            expect:
              - statusCode: 200
              # - contentType: json
            afterResponse: "logResponse"

When executing load test enter image description here

As you can see above the userId, this works fine on postman with all the credentials but not when executing load test. Maybe I am missing something in script. Been stuck on this for a whole day. tried different users, API endpoints, no luck.

Tried another script with same API endpoint, subscription key, authorization key which works as the other is for login instead of entity retrieve form.

Below load test for login users works fine when performing load test but for the entityRetrieve form is not working. To note that i can't use user & pass for the entityRetrieve form as I used for login. I am using userId as on postman.

This is for login which works fine , load test works.

config:  
      
      target: 'API endpoint'
      timeout: 180

      payload:
        path: "Users.csv"
        fields:
            - "email"
        order: sequence
        skipEmptyLines: true

      phases:
        - duration: 4
          arrivalCount: 2
         # arrivalRate: 1
          

      defaults:
        headers:
          Ocp-Apim-Subscription-Key: '77ede57299824292aa719d82b194c83a'
          Content-Type: 'application/json'
          Cache-Control: 'no-store'
          

      processor: "my-functions.js"
    scenarios:
      - flow:
      # start
        - log: "Login - Get Form"
        - post:
            url: '/Crm/GetForm'
            body: '{
              "formId": "8e983cb7-6ffa-42e2-8c41-7d46432785a8",
              "formType": "Login",
              "locale": "en-US"
            }'
            afterResponse: "logResponse"
        - think: 3
      # stop
        - log: "Login - User Action"
        - post:
            url: '/Crm'
            beforeRequest: "logBodyReq"
            body: '{"locale": "en-US",
              "formType": "Login",
              "Params": {
                "signInEmailAddress" : "{{email}}",
                "currentPassword" : "Testing123" 
              } }'
            expect:
              - statusCode: 200
              # - contentType: json
            afterResponse: "logResponse"

1

There are 1 answers

0
bernardobridge On

Set the defaults using config.http.defaults.headers, as shown here. So:

config:  
  http:
    defaults:
      headers:
        Ocp-Apim-Subscription-Key: "ABC123"
        Content-Type: "application/json"
        Cache-Control: "no-store"

It's also possible your body isn't being set correctly. Try setting the body using json instead, as shown here: https://www.artillery.io/docs/reference/engines/http#get--post--put--patch--delete-requests .

So, for example:

- post:
    url: '/Crm'
    beforeRequest: "logBodyReq"
    json:
      locale: "en-US"
      formType: "Login"
      Params:
        signInEmailAddress: "{{ email }}"
        currentPassword: "Testing123"