3

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.

Community
  • 1
  • 1
physicsboy
  • 5,656
  • 17
  • 70
  • 119
  • [YML](https://fdik.org/yml/) is not the same as [YAML](https://yaml.org/spec/1.2/spec.html) and the recommended extension for YAML files has been `.yaml` at least since Sep 2006. The example you quote used the proper filename, which you seem to have misread/misrepresented in the rest of your post.. – Anthon May 09 '19 at 14:38
  • @Anthon - Whoops. Mixing web examples and my own codebase there. Edited to be consistent now. Any thoughts on the matter, other than syntactic mistakes on my part? – physicsboy May 09 '19 at 14:39
  • Sorry, but no. I get notified on posts tagged with [tag:yaml] (as I developed a Python load/dumper package for YAML), but I don't know Artillery. – Anthon May 09 '19 at 14:47
  • 1
    @Anthon apologies, clicked the first one I saw. Have changed the tag to app.yaml now. – physicsboy May 09 '19 at 14:51

3 Answers3

3

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
simon
  • 854
  • 1
  • 9
  • 23
  • Is there a way in which you would be able to specify multiple variables? – physicsboy May 24 '19 at 07:08
  • You could split up a common-config.yml as another option. See --config section here: https://artillery.io/docs/cli-reference/ – simon May 31 '19 at 19:16
0

IDK why but for me export worked, I mean:

"scripts": {
    "start": "export ENV=https://yoursite.com&&artillery run -k yourtest.yml"
}
Rene Enriquez
  • 1,418
  • 1
  • 13
  • 33
0

Something perhaps not very sophisticated but that works is this:

config:
  target: "https:/"

Then in the url you can put the rest of the URL for each cases

- get:
    url: "/myUrl1.com"

- get:
    url: "/myUrl2.com"
Vict01
  • 300
  • 1
  • 10