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.87k stars 501 forks source link

Problem with JSONPath queries #355

Open markb-trustifi opened 7 years ago

markb-trustifi commented 7 years ago

I receive an array of data from a http response:

[{_id:"aaaaaa"},{_id:"bbbbb"},{_id:"ccccc"}]

These expressions are supposed to print an array of _id's but I get only single value: $.._id $[0,2]._id

This expression is supposed to print a length of an array but prints the whole expression "$.length": $.length

singerxt commented 5 years ago

Hello!

I'm experiencing same issue. Looks like there is no way to receive array of values even if JSON path supports that. I took a look at code and looks like this is expected behaviour https://github.com/artilleryio/artillery/blob/master/core/lib/engine_util.js#L499. Looks like if we receive multiple values from JSON path code is choosing random value.

Can I know what is a reason behind this piece of code ?

jspark-gigworks commented 3 years ago

In the function of extractJSONPath() in engine_util.js, it takes a random value if the result is an array which length is more than 1.

  if (results.length > 1) {
    return results[randomInt(0, results.length - 1)];
  } else {
    return results[0];
  }

I suggest that this behavior(picking ramdom one) should be only applied as a property such as randomPick: true. I think many users may want to use a full array itself not an item which is picked randomly.