Hi All,
I am trying to build the header values as map in a function, as there is a dynamic value I need to use. But I am getting the compilation errors - “missing parameter type” at “.headers(Session => getBrowseAppsHeader(Session(“mindevice”).as[String].toInt, Session(“maxdevice”).as[String].toInt))”. Following is the code snippet which gives the compilation errors. Can any one help me on this?
def getBrowseAppsHeader(minDevice:Int, maxDevice:Int): Map[String, String] = {
val rnd = new scala.util.Random
val AndDeviceRange = minDevice to maxDevice
val AndDeviceID = AndDeviceRange(rnd.nextInt(AndDeviceRange.length))
val BrowseAppsHeader: Map[String, String] = Map(
“deviceid” → AndDeviceID.toString(),
“devicemodel” → DEVICEMODEL,
“devicename” → DEVICENAME,
“osversion” → OSVERSION,
“Content-Type” → contentType,
“Accept” → JSonResponseType,
“userid” → EMMPerfConfig.guserid,
“platformid” → “ANDROID”
)
BrowseAppsHeader
}
val execBrowseApps = exec(http(“Browseapps”)
.post("${tenantname}%sdevice/rest/browse/apps".format(context))
.headers(Session => getBrowseAppsHeader(Session(“mindevice”).as[String].toInt, Session(“maxdevice”).as[String].toInt))
.body(StringBody(browseAppReqBody))
.check(status.is(200))
.check(jsonPath("$.opstatus").is(“0”))
What you try to build to my understanding is not allowed currently. The “headers” does not accept Expression[Map[String, String]] by definition:
http://gatling.io/docs/current/http/http_request/#headers
https://github.com/gatling/gatling/blob/a3d2f4b44ac292931599a1b6c4cb72515d7a4e96/gatling-http/src/main/scala/io/gatling/http/protocol/HttpProtocolBuilder.scala#L85-L86
headers(newHeaders: Map[String, String])
You may find alternative solution in a recent post about this topic:https://groups.google.com/forum/#!msg/gatling/YEsQ_YNo0eE/KfARQf3pAwAJ
Or file a feature change request for Stephan et team?
Thank you for your reply. I have actually tried this as well, but got the same error. Currently I modified the code as follows, as a workaround.
def getBrowseAppsHeader(): Map[String, String] = {
val BrowseAppsHeader: Map[String, String] = Map(
“devicemodel” → DEVICEMODEL,
“devicename” → DEVICENAME,
“osversion” → OSVERSION,
“Content-Type” → contentType,
“Accept” → JSonResponseType,
“userid” → EMMPerfConfig.guserid,
“DEVICE_PLATFORM_ID” → “ANDROID”
)
BrowseAppsHeader
}
def getDynamicDevice(minDevice:Int, maxDevice:Int): String = {
val rnd = new scala.util.Random
val AndDeviceRange = minDevice to maxDevice
val AndDeviceID = AndDeviceRange(rnd.nextInt(AndDeviceRange.length))
s"""${AndDeviceID}"""
}
.header(“deviceid”, Session => getDynamicDevice(Session(“mindevice”).as[String].toInt, Session(“maxdevice”).as[String].toInt))
.headers(getBrowseAppsHeader())
Thank you
Dinesh