How to i pass a dynamic variable in an API URL in Artillery.io

761 Views Asked by At

I need to run a load test on artillery.io - the api will basically contain a query string as follows:

https://<<thisishowtheurllookslie/username?id=AXXXX1

Basically,

https://<<thisishowtheurllookslike/username?id=AXXXX1 is the record for user AXXXX1
https://<<thisishowtheurllookslike/username?id=AXXXX2 is the record for user AXXXX2
https://<<thisishowtheurllookslike/username?id=AXXXX3 is the record for user AXXXX3
https://<<thisishowtheurllookslike/username?id=AXXXXN is the record for user AXXXXN

I need to run a load test with N number of users - my belief is i need to create a CSV file starting with AXXX1 to AXXXN rows .

How to I configure all this in the yml file?

So far my config looks like this:

config:
  target: https://<<thisishowtheurllookslike/username?id=AXXXX1
  phases:
    - duration: 60
      arrivalRate: 1
    - duration: 300
      arrivalRate: 10

I am unable to understand how to make username as dynamic in the the URL

1

There are 1 best solutions below

5
bernardobridge On

You should set your base URL in the target, and then set the path in the scenario using variable substitutions, with variables you can set in the Config.

scenarios:
  - flow:
      - get:
          url: "/username?id={{ myVariable }}"

(you can also use querystring instead of setting them in the URL)

You can also load the variable from the csv using the same mechanism and the payload functionality: https://www.artillery.io/docs/reference/test-script#payload---loading-data-from-csv-files