Add several post paremeters from a list

Hi,

I am trying to create scenario containing a post request with parameters that comes from a previous request.
For now I store those parameters as a list in the session using a regexp on the first request.

I am new to scala and gatling and I cannot find a way to create the post request using the “list” stored in the session and “dynamically” add the parameters.

My first idea is to loop on the list and add params to a base PostHttpRequestBuilder.

Thanks

Olivier

Hello,

Is there a way you can share your current script ?

cheers
Nicolas

Hi,

What do you want to do exactly:

  • do you want to add one of the values of the list as a monovalued parameter, or
  • do you want to add all of them as a multivalued parameter?
    Cheers,

Stéphane

2012/9/26 Nicolas Rémond <nicolas.remond@gmail.com>

Hi,

I want to add all of them as a multivalued parameter.

I tried to create several request builder using a foldLeft on the value list :

myValueList.foldLeft(baseRequestBuilder) { (requestBuilder: PostHttpRequestBuilder, value: String) => {
requestBuilder.param(""“select”"", value)
}

But I can’t understand how to execute the last builder created in that “loop” …

Cheers.

Olivier

Hi Olivier,

Please see this issue:
https://github.com/excilys/gatling/issues/750

Let’s say you have a multivalued session attribute named “foo”, obtained fro example from a regex.findAll.

You can now write .multiValuedParam(“foo”) or .multiValuedParam(“anotherName”, “foo”)

I honestly haven’t tested it yet (I’m more or less on vacation…), but you can grab it in the latest snapshot:
http://repository-gatling.forge.cloudbees.com/snapshot/com/excilys/ebi/gatling/highcharts/gatling-charts-highcharts/1.3.1-SNAPSHOT

Please let us know if it helps.

Cheers,

Stéphane

2012/9/28 Olivier Bearn <obearn@gmail.com>

Regarding the scala code you wrote, it works only if your parameter values list is static, ie exists when building the Simulation.
In that case, you were almost there: the complete requestBuilder is the value returned by foldLeft. You can either “exec” it or add checks or whatever on it.

With the new API, you can write .multiValuedParam(“foo”, List(“bar”, “baz”))

Steph

2012/9/28 Stéphane Landelle <slandelle@excilys.com>

Thanks,

I will give it a try.

I still think it would be nice to have a way to create the builders dynamically in an exec with the session available in the scope.

Cheers

Olivier

2012/9/28 Stéphane Landelle <slandelle@excilys.com>

I know but the list was actually extracted from the session.

I used static vars so I could reference the list from everywhere in the simulation builder.
The thing is the initial baseRequestBuilder “var” reference was passed to the exec at the end and I couldn’t make the new “var” reference get executed by an exec.

As I told you I am new to scala and functional programming :).

Olivier

2012/9/28 Stéphane Landelle <slandelle@excilys.com>

Well, lack of multivalued parameters support was definitely an issue, so I added in the DSL.
What you propose would actually be quite the Pandora box, so I still need to see a concrete use case for this.

2012/9/28 Olivier Bearn <obearn@gmail.com>

No, you can’t do it this way, sorry. :wink:

What you’d need would be a good understand of Gatling inner HTTP API and that we add a hook that let you access the ProtocolConfigurationRegistry required for building an HttpRequestBuilder.
The current hook exec(Session => Session) doesn’t have this parameter.

So, it is almost feasible, I’d just like to get a real use case for this.

Cheers,

Steph

2012/9/28 Olivier Bearn <obearn@gmail.com>