Till now we have read about the artillery and the HTTP load testing in artillery. There are many ways to execute artillery scripts, a quick test, a simple run or run with some over-rides. Lets see some different ways to execute artillery script :
Run a quick test
Artillery allows users to run custom test scripts written in either yaml or json, users can also perform a quick test without loading external scripts. The following command specifies 20 GET requests to be sent every second for 10 seconds creating 10 virtual users per request.
artillery quick –count 10 -n 20 https://your-local-site-to-be.tested
Run a simple test
The following yaml file can be executed to achieve a simple run bu using artillery run your.yaml
config: target: https://your-website-link phases: - duration: 10 arrivalRate: 10 scenarios: - flow: - get: # add the url you need to send get request url: "/" capture: # capturing responce using reg expression - regexp: "[^]*" as: "response" - log: "response= {{response}}"
This command run the yaml file and sets a load of 10 users for 10 seconds to the given target. The duration and user count can be changed by changing the values of “duration” and “arrivalRate” respectively.
Test with output
We can run the artillery test stating the output of result in a file. The output of test always returns a json file, the path of the file should be with in retailed to the path of yaml file. The following command run artillery test with output file named as “report.json” and the path of file is given relative to the path of test script.
artillery run -o ‘report.json’ test.yaml
This command will give the test output and will generate a report with name ‘report.json’. The outpot will be something like :
Started phase 0, duration: 10s @ 14:27:36(+0530) 2018-08-13 Report @ 14:27:38(+0530) 2018-08-13 Scenarios launched: 10 Scenarios completed: 10 Requests completed: 10 RPS sent: 2.13 Request latency: min: 401 max: 401 median: 401 p95: 401 p99: 401 Codes: 200: 100 Log file: report.json
Test with overrides
In many situations it would be useful to adjust some of the values in the config section. To achieve the same, we can use -overrides in artillery.This option is used to override parts of the test script, for example, we need to override the phase definitions in the test script. We can use:
artillery run –overrides ‘{“config”: {“phases”: [{“duration”: 10, “arrivalRate”: 1}]}}’ test. yaml
test.yaml
config: target: https://your-website-link phases: - duration: 100 arrivalRate: 100 scenarios: - flow: - get: # add the url you need to send get request url: "/" capture: # capturing responce using reg expression - regexp: "[^]*" as: "response" - log: "response= {{response}}"
Here in the test script, the duration and the arrivalRate are set to 100. When we run the above commad in the command line, the duration and arrivalRate are overridden by 10 and 1 respectively.
Test with passing Variables
artillery run -v ‘{“size”: [“small”, “medium”, “large”], “color”:[“black”, “blue”]}’ test.yaml
Makes variables “size” and “color” available in scenarios, with values picked from the respective lists. If the variables are present in the yaml file, they will be overridden by the provided variables. This overriding of variables could be done to test new values to the data.
Test with reports
artillery run -o report.json mytest.yaml
artillery report report.json
The command -o <report_name> will generate the report after completion of the test.This report will be generated in json file and could be generated to html file.
The above were the different ways to run artillery scripts.
Suggestion are appreciated in the comments 😀
Task)
Create ramp up arrival rate from 10 to 20 over 1 minute to create the user account. Define the variable request URL, name, and job in the Inline variable. Search the newly created user using ID. Use Reqres application as base and request URL.
Need script for the above one