Anshika Jain
Anshika Jain

Reputation: 177

How to append apis with incrementing numbers

How can I hit multiple apis like example.com/1000/getUser, example.com/1001/getUser in Gatling? They are Get calls. Note: Numbers start from a non zero integer.

Upvotes: 0

Views: 245

Answers (1)

Hard to give good advice based on the small amount of information in your question, but I'm guessing that passing the userID's in with a feeder could be a simple, straightforward solution. Largely depends on how your API-works, what kind of tests you're planning, and how many users (I'm assuming the numbers are userId's) you need to test with.

If you need millions of users, a custom feeder that generates increments would probably be better, but beyond that the strategy would otherwise be the same. I advice you to read up on the feeder-documentation for more information both on usage in general, and how to make custom feeders: https://docs.gatling.io/reference/script/core/session/feeders/

As an example, if you just need a relatively small amount of users, something along these lines could be a simple, straightforward solution:

Make a simple csv file (for example named userid.csv) with all your userID's and add it to the resources folder:

userid
1000
1001
1002
...
...

The .feed() step adds one value from the csv-file to your gatling user session, which you can fetch as you would work with session values ordinarily. Each of the ten users injected in this example will get an increment from the csv-file.

setUp(
  scenario("ScenarioName")
    .feed(csv("userid.csv"))
    .exec{http("Name of your request").get("/${userid}/getUser")}
  )
  .inject(
    atOnceUsers(10)
  )
).protocols(http.baseUrl("example.com"))

Upvotes: 0

Related Questions