I am trying to pass today's date in Gatling Body using session.set but no success
I have below code where using joda-time(https://www.joda.org/joda-time/) timestampfeeder variable is set
class gamekeeper extends BaseSimulation {
val timestampFeeder: String = DateTimeFormat.forPattern("yyyy-MM-dd").print(DateTime.now())
exec { session => session.set( "TimestampFeeder", timestampFeeder )}
val createPrivateEvent ={
exec(
http("Create Event As WER")
.post("https://api.cloud/" + {Env} + "/silve-griffin-service/graphql")
.headers(header)
.body(ElFileBody("<filename>"))
.check(status.in(200,201))
.check(bodyString.saveAs("EventAsWER_Response"))
.check(jsonPath(path="$.data.createEvent.id")
.saveAs(key="EventId")
)
)
.exec { session => session.set("NEW_ID", session("EventId").as[String]) }
.exec{session=>println(session);session}
//.pause(40,50)
}
val scenario4 = scenario("Full GameKeeper tests“)
.exec(createPrivateEvent)
setUp(
scenario4.inject(
constantConcurrentUsers(userCount) during(testDuration))
.protocols(httpProtocol)
)
.maxDuration(testDuration)
}
Here are the contents of createeventasWERwithcurrentdatetime.txt
{
"query": "mutation createEvent($input: CreateEventInput!) {\n createEvent(input: $input) {\n ...EventFields\n __typename\n }\n}\n\nfragment EventFields on Event {\n id\n status\n title\n format\n limitedSet\n rulesEnforcementLevel\n pairingType\n entryFee {\n amount\n currency\n __typename\n }\n venue {\n id\n name\n latitude\n longitude\n address\n timeZone\n phoneNumber\n emailAddress\n __typename\n }\n capacity\n description\n scheduledStartTime\n estimatedEndTime\n latitude\n longitude\n address\n timeZone\n phoneNumber\n emailAddress\n shortCode\n __typename\n}",
"variables": {
"input": {
"organizationId": "14540",
"latitude": 47.66499,
"longitude": -122.38043,
"phoneNumber": "206-523-9605",
"emailAddress": "test@gameot.com",
"title": "PerfTestServicesEvent",
"format": "DRAFT",
"pairingType":"SWISS",
"limitedSet": "CORE2020",
"rulesEnforcementLevel": "CASUAL",
"entryFeeAmount": 500,
"entryFeeCurrency": "USD",
"venueId": null,
"capacity": 8,
"description": "test",
"timeZone": "America/Los_Angeles",
"scheduledStartTime": ${TimestampFeeder},
"estimatedEndTime": "2020-02-15T16:00Z"
}
}
}
Seems No success in value substitution ,why session.set is not able to replace the value of TimestampFeeder
The reason that your variable setting doesn't work is that the exec to run that session function isn't chained to or called by anything else - it's just defined in the middle of the gamekeeper class.
You also seem to be confused about feeders - unless you're using the gatling construct of this name, it's probably best to call it something else.
You can easily get this working by having a session function that sets the date and including it at the start of the scenario.
val scenario4 = scenario("Full GameKeeper tests“)
.exec(session => session.set("TimestampFeeder",DateTimeFormat.forPattern("yyyy-MM-dd").print(DateTime.now())
.exec(createPrivateEvent)
I don't think you can used your existing TimestampFeeder val as it's only going to get set once at the start of the run - you'd have to make it a function if you want to structure things that way.