Examples for Before and After Each

Hi,

I am trying to define some scenarios in before and after block

like this

before {
scenario("Example 1’).exec(http(“Create some data”).post(“someUrl”).body({“key”: “value”}).asJSON).inject(atOnceUsers(1))
}

after {
scenario("Example 1’).exec(http(“Delete some data”).delete(“someUrl”)).inject(atOnceUsers(1))
}

when i run test I am not able to see that these requests are being executed.

Then i tried doing like this

before {
SetUp(scenario("Example 1’).exec(http(“Create some data”).post(“someUrl”).body({“key”: “value”}).asJSON).inject(atOnceUsers(1)))
}

after {
SetUp(scenario("Example 1’).exec(http(“Delete some data”).delete(“someUrl”)).inject(atOnceUsers(1)))
}

and got an error setUp can be called only once in simulation.

Can someone here help me to execute Http Requests in before and after blocks

Thanks

Documentation is here: http://gatling.io/docs/2.0.0/general/simulation_structure.html#hooks

Hi there!

Please refer to the latest documentation page (http://gatling.io/docs/2.2.1/general/simulation_structure.html#hooks):

Note

You won’t be able to use Gatling DSL in there, as it’s only intended for load test. You can only use your custom code.

So basically it´s not possible to use your existing scenarios here, you have to write your own code that would create an http client and make the request you need.

Regards,
Aleksei

before {
scenario("Example 1’).exec(http(“Create some data”).post(“someUrl”).body({“key”: “value”}).asJSON).inject(atOnceUsers(1))
}

after {
scenario("Example 1’).exec(http(“Delete some data”).delete(“someUrl”)).inject(atOnceUsers(1))
}

I was trying to execute some Gatling DSL in the before and after blocks, but they are not getting executed.

can some explain what kind of code can be executed in the before and after block