10

I have a Gatling test which should do the following:

  1. create user once
  2. retrieve user's data according to specific load model. Actual load testing.
  3. delete user after when done

Question: how to emulate this with Gatling? If I chain calls like :

val scn = scenario("Test scenario").exec(_create-user_).exec(_retrive-user_).exec(_delete-user_)
setUp(scn).protocols(httpConf))

then creating and deleting user will be part of the test.

Fedor
  • 559
  • 1
  • 7
  • 19

2 Answers2

18

You can use the before and after hooks to create and delete the user.

class RetrieveUserSimulation extends Simulation {

  before {
    // create user
  }

  setUp(scn).protocols(httpConf)

  after {
    // delete user
  }

}

You'll have to issue the create and delete HTTP requests manually. before and after take => Unit thunks, not Scenarios.

David B.
  • 5,700
  • 5
  • 31
  • 52
  • I tried something similar here https://stackoverflow.com/questions/63386159/gatling-exec-outside-scenario-scope-post-requests-are-not-called but I don't see POST requests only the one in the scenario – Saher Ahwal Aug 13 '20 at 00:20
0

In before hook we can call a method which can have below code.

val httpClient = HttpClientBuilder.create.build
val httpResponse = httpClient.execute(new HttpPut(urlString))
println("StatusCode - " + httpResponse.getStatusLine.getStatusCode)
httpClient.close()

We can use HttpGet as well. Here used apache library

example : org.apache.http.impl.client.HttpClientBuilder
Jared Forth
  • 1,577
  • 6
  • 17
  • 32
Nalin
  • 1
  • 2