artilleryio / artillery

The complete load testing platform. Everything you need for production-grade load tests. Serverless & distributed. Load test with Playwright. Load test HTTP APIs, GraphQL, WebSocket, and more. Use any Node.js module.
https://www.artillery.io
Mozilla Public License 2.0
7.88k stars 501 forks source link

config variables cant be used in json lists #645

Open pithu opened 5 years ago

pithu commented 5 years ago

I wonder why config variables cant be used in json lists, is that a bug ?

I track down my issue to the following configuration:

config:
  target: "http://localhost"
  phases:
    - duration: 1
      arrivalRate: 1
  variables:
    foo: "bar"
scenarios:
  -
    flow:
      - log: "{{ foo }}"
      - log:
          foo: "{{ foo }}"
      - log:
        - "{{ foo }}"

log output is:

⠹ bar            // as expected
{ foo: 'bar' }   // as expected
[ '{{ foo }}' ]  // expect [ 'bar' ] here

substitution in strings and json objects worx, but in json lists not

hassy commented 5 years ago

That's specific to the log action which expects a string - but really there's no reason it shouldn't work with lists or objects!

pithu commented 5 years ago

Hello @hassy, first of all thanks for the quick reply and for providing this awesome tool.

The issue is specific for all json objects, currently its not possible to use variables in a list context at all. For example substitution in a rest call with a list schema do not work:

config:
  ...
  variables:
    foo: "bar"
  scenarios:
    - flow:
      - post:
          url: '/items'
          json:
            items:
              - "{{ foo }}"

sends { items: ["{{ foo }}"] } instead of expected { items: ["bar"] }.

I couldn't find a work around, does anyone has an idea how to send a list with a variable in it?

Or could you provide a code pointer, for a good place to fix it, so i could try.

Thanks in advance

sidsalunke commented 5 years ago

Hi @pithu. I've raised a similar issue -> https://github.com/artilleryio/artillery/issues/644 You can find a workaround in the issue itself or you can go here -> https://github.com/artilleryio/artillery/issues/250#issuecomment-378384577 Hope this helps.