How to add dynamic params?

Hi,

I have multiple hidden fields that are generated automatically:

And i use regex to collect values:
.check(regex(""“hdnUser” value="([\w=/.\d_%±.]*)"""").findAll.saveAs(“hdnUser”))

I can access “hdnUser” session to get values:
.exec(session => {
var users = session(“hdnUser”).as[Seq[String]]
users.foreach(user => {
println(user)
})
session
})

Now, I’d like to add them to params dynamically in next post as below, how can i achieve this by using session(“hdnUser”) above?
.exec(http(“request_13”)
.post("""/Activate.aspx""")
.param(""“ctl00$PlaceHolderMain$dtlUsers$ctl00$hdnUser”"", “”“pa0"”")
.param(""“ctl00$PlaceHolderMain$dtlUsers$ctl01$hdnUser”"", “”“pa1"”")
.param(""“ctl00$PlaceHolderMain$dtlUsers$ctl02$hdnUser”"", “”“pa2"”")
.param(""“ctl00$PlaceHolderMain$dtlUsers$ctl03$hdnUser”"", “”“pa3"”")

Thanks in advance.

Is it expected that input names and param names differ ($ instead of _)?

ctl00_PlaceHolderMain_dtlUsers_ctl00_hdnUser vs ctl00$PlaceHolderMain$dtlUsers$ctl00$hdnUser

I’m using asp.net and server generate id with “_” and name with “$”. When post to server, it just recognize “$” so we must use “ctl00$PlaceHolderMain$dtlUsers$ctl00$hdnUser” for param in post.
I was able to achieve this by:
.paramsSeq(session=>{
var users = session(“hdnUser”).as[Seq[String]]
var b = Seq((“b”,“5”),(“c”,“4”))
var i = 0;
users.foreach(user => {
var name = “ctl00$PlaceHolderMain$dtlUsers$ctl0”+ i.toString +"$hdnUser"
b = b :+ (name, user.name)
i = i + 1;
})
b
})

Thanks for your help.

Oups, sorry.

A proper solution with upcoming version is to use a regex with 2 capture groups (one for name and one for value):
https://github.com/excilys/gatling/blob/master/src/sphinx/http/http_check.rst#http-response-body

regex("foo(.*)bar(.*)baz").ofType[(String, String)]

and then directly post the pairs:

  • paramsSeq(seq: Expression[Seq[(String, Any)]])

Sorry,

regex(""“hdnUser” value="([\w=/.\d_%±.]*)"""")…ofType[(String, String)]

throw error:
value ofType is not a member of io.gatling.http.check.HttpMultipleCheckBuilder[CharSequence,String]
regex(""“hdnGroupLevel” value="([\w=/.\d_%±.$]*)"""").ofType[(String, String)],
^

i’m using Gatling 2.0.0-SNAPSHOT.

You use an old snapshot. HttpMultipleCheckBuilder doesn’t even exist anymore.

I’m get Gatling from Maven:


sonatype
Sonatype OSS
https://oss.sonatype.org/content/groups/public

true




<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.6</maven.compiler.target>
<scala.version>2.10.4</scala.version>
UTF-8

<gatling.version>2.0.0-SNAPSHOT</gatling.version>
<gatling-highcharts.version>2.0.0-SNAPSHOT</gatling-highcharts.version>

<scala-maven-plugin.version>3.1.6</scala-maven-plugin.version>

Where can i get latest?

see https://github.com/excilys/gatling/issues/1821