最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Using global variables across YAML files within Artillery - Stack Overflow

programmeradmin4浏览0评论

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 mand.

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 mand.

Share Improve this question edited Jun 20, 2020 at 9:12 CommunityBot 11 silver badge asked May 9, 2019 at 13:30 physicsboyphysicsboy 6,37822 gold badges77 silver badges139 bronze badges 4
  • YML is not the same as YAML and the remended 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 Commented May 9, 2019 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 Commented May 9, 2019 at 14:39
  • Sorry, but no. I get notified on posts tagged with yaml (as I developed a Python load/dumper package for YAML), but I don't know Artillery. – Anthon Commented May 9, 2019 at 14:47
  • 1 @Anthon apologies, clicked the first one I saw. Have changed the tag to app.yaml now. – physicsboy Commented May 9, 2019 at 14:51
Add a ment  | 

5 Answers 5

Reset to default 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.&&artillery run -k yourtest.yml"
}

in the .yml file itself something like this:

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

call it like this:

npm run start

IDK why but for me export worked, I mean:

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

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."

- get:
    url: "/myUrl2."

Apparently, you can use "{{ $env.VAR_NAME }}".

I prefer to create an environment (.env) file with environment variables and then specify the environment file to use at runtime.

File (dev.env)

#Targets
TARGET_MAIN = "http://asciiart.artillery.io:8080/"

#Keys
ARTILLERY_CLOUD_API_KEY = "a9_NFs391iKxxxxxxxxxxxxxxxx"

#Durations
DURATION_DEFAULT = 30

#Arrivals
ARRIVAL_DEFAULT = 1

#RampCounts
RAMP_DEFAULT = 2

(Then in the yaml test file)

config:
  target: "{{$env.TARGET_MAIN}}"
  phases:
    - duration: "{{$env.DURATION_DEFAULT}}"
      arrivalRate: "{{$env.ARRIVAL_DEFAULT}}"
      rampTo: "{{$env.RAMP_DEFAULT}}"

Lastly to run the test with the environment file:

artillery run --env-file dev.env test.yml

I prefer this approach because I can also easily switch between dev testing parameters and prod testing parameters by changing the env file used.

发布评论

评论列表(0)

  1. 暂无评论