Artusamak
Artusamak

Reputation: 2510

Gatling / Scala remove Vector from string value in POST request

I'm trying to send a POST request within a Gatling test. 2 values have to be sent, the first one is extracted from my page content, the second one is hardcoded.

My issue is that when i extract a value from my page content, i end up with a string submitted in my POST request but polluted with the "Vector()" wrapper.

Here is my scenario and how my variable is extracted:

val dossier = exec(http("Content creation - Extract vars")
  .get("/node/add/dossier")
  .check(css("""input[name="form_token"]""", "value").findAll.saveAs("form_token_node"))
  .headers(headers_0))
  .pause(2)
  .exec(http("Content creation")
  .post("/node/add/dossier")
  .headers(headers_1)
  .formParam("form_token", "${form_build_id_node}")
  .formParam("form_id", "node_dossier_form")
  .check(status.is(303))
)

And here is how the data look like when they are sent in the POST request:

As you can the the form_token variable should not look like this at all, it's breaking the form submission for a unvalid reason.

So my question is, how do i get ride of the Vector() part of the string?

And the answer is use ${form_build_id_node(0)} instead of ${form_build_id_node} to access to the value. Thanks to sschaef.

Upvotes: 1

Views: 636

Answers (1)

Monika Rajendran
Monika Rajendran

Reputation: 33

Here the issue is at saving the attribute. you have used .findAll.saveAs - Which will save as list taking all the occurrences

If you want to pass only the first occurrences, then it should be

.check(css("""input[name="form_token"]""","value").saveAs("form_token_node"))

instead of

.check(css("""input[name="form_token"]""","value").findAll.saveAs("form_token_node"))

if your going to use foreach or repeat to get more values then you can .findAll.saveAs list and create a logic to iterate the session attribute ${form_build_id_node(i)} in your scenario

Upvotes: 1

Related Questions