Skip to content
Advertisement

Using global variables across YAML files within Artillery

Is there any way in which I can say, define a URI that will be used in different .yml files for different Artillery load tests?

I am wanting to use the same URI within a number of .yml files to define the target within the config section.

I saw the following on the Artillery docs:

Values can be set dynamically via environment variables which are available under $processEnvironment template variable.

For example, to set a default HTTP header for all requests via the SERVICE_API_KEY environment variable

They show an example doc of:

export SERVICE_API_KEY=”012345-my-api-key”

artillery run my-test.yml

However I am unsure of how to implement this, as I am using the package.json file to run the artillery run my-test.yml command.

Answer

Figured this out on my own:

In package.json make a new script. Call it whatever you like, and do something similar to this:

"scripts": {
    "start": "set ENV=https://yoursite.com&&artillery run -k yourtest.yml"
}

in the .yml file itself something like this:

config:
  target: "{{$processEnvironment.ENV}}"

call it like this:

npm run start
Advertisement