Artillery: Is beforeRequest hooks run before or after variable substitution?

Created on 30 Sep 2016  路  7Comments  路  Source: artilleryio/artillery

Hello,

I am trying to use some JS logic to inject templated JSON payload in the request at runtime. This is for making more automatic the task of use new payloads and smaller config files.
I wanted to use variables within the JSON templates that I inject, but this will be only possible if beforeRequest hooks runs before variable substitutions are performed.

Could you please clarify this point? If it is not already possible, would it be possible to introduce another hook that runs before variable substitution?

Thanks an regards

http enhancement

Most helpful comment

Hello @hassy ,

I do understand that fact, I also deducted that after a while. But it is confusing that you have access to the environment variables on the beforehooks and that you can change them there. You should clearly specify that changing variables from the before hook will have no effect on the variable substitution, and maybe some other places that I didn't think about. Somebody (like me) could infer that if you can change it, you can take advantage of it.

thanks and regards

All 7 comments

Those run after variables have been substituted already. Yeah, we can add a beforeTemplate hook (or something named along those lines).

In my tests it is happening that variable substitution is not being performed if I inject something in the context.vars
What is the point of being able to inject something into vars if it will not be used?

Are you modifying the variable (or adding a new one) in the step before the one where you're using it?

Hello @hassy ,

Are you modifying the variable (or adding a new one) in the step before

At first I was not, because the authorization hook runs at scenario level, and the one injecting some variables being used on the url was running at petition level. But now that I have moved the variable injector to scenario level too, and I put it before in the array of hooks the result is exactly the same: If I inspect the requestParams the variables are there, but the variables at the uri are just empty strings

- beforeRequest:
        - "injectLatLon"
        - "authorizeRequest"
  flow:
        - get:
            url: "/grids/{{ lat }}/{{ lon }}"

That is one of my flows. If I put a breakpoint on authorizeRequest the uri is http://localhost/grids//

As mentioned above beforeRequest runs after the substitutions have already been performed, that's why it doesn't work. We need a hook for before the substitutions are performed for your use case.

Hello @hassy ,

I do understand that fact, I also deducted that after a while. But it is confusing that you have access to the environment variables on the beforehooks and that you can change them there. You should clearly specify that changing variables from the before hook will have no effect on the variable substitution, and maybe some other places that I didn't think about. Somebody (like me) could infer that if you can change it, you can take advantage of it.

thanks and regards

Was this page helpful?
0 / 5 - 0 ratings

Related issues

JohnieLee picture JohnieLee  路  3Comments

ooii picture ooii  路  5Comments

BharaniRanganath picture BharaniRanganath  路  3Comments

DanielMSchmidt picture DanielMSchmidt  路  4Comments

hassy picture hassy  路  3Comments