Call external .exec block

Hi,

I am trying to modularize my code and have multiple simulations use a common external file they can call .exec blocks from. Is this something that Gatling can handle?

For example, I want simulations A and B to use a .exec I have defined on a separate file, possibly on a function.

externalFile.scala

def create(session:Session) = Session {
.exec(
http(“Create User”)
.put(“blah”)
.headers(headers)
.check(status.is(200))
)

}

simulationA.scala imports externalFile.scala



//create user
.exec(session => create(session))

simulationB.scala imports externalFile.scala



//create user
.exec(session => create(session))

Thank you so much for the help!

Me doing it a lot in my tests. Basically, I’ve created a library containing most common things that can be performed in an app i’m testing, and then use it just like lego in actual test scenarios)

You can define something like this in a separate object (e.g. called TestSteps):
def createSession: ChainBuilder = {
//you can put one or several requests here, or requests groups or whatever
exec(
http(“Create User”)
.put(“blah”)
.headers(headers)
.check(status.is(200))
)
}

Then you call it somewhere in your scenario:
exec(TestSteps.createSession)

Best practice for this is applying page object pattern (or resource object pattern)

Apologies for the late response but thank you so much. This is working well!
Have a good day!