Variable not set but I can print values in debug

Hello. I need help in resolving issue with one variable not being set.
Here is my code:

.foreach("#{programUrls}", "programUrl") {
  exec(http("vote citation")
    .get("#{programUrl}")
    .check(status.is(OK))
    .check(substring("Citation Voting").exists)
    .check(substring("My Vote on This Citation").exists)
    .check(css("input[name='form_build_id']", "value").findAll.saveAs("formBuildIds"))
    .check(css("input[name='form_token']", "value").findAll.saveAs("formTokens"))
    .check(css("input[name='form_id']", "value").findAll.saveAs("formIds"))
    .check(css("input[value='Accept']", "name").findAll.saveAs("acceptButtons")))
    .exec(session => {
      println("*************************************************************************************************")
      println(session("acceptButtons").as[String])
      println("*************************************************************************************************")
      session
    }
    )
  .foreach("#{formBuildIds}", "citation", "counter") {
    exec(http("accept citation")
      .post("#{programUrl}")
      .queryParam("ajax_form", "1")
      .queryParam("_wrapper_format", "drupal_ajax")
      .formParam("form_build_id", "#{formBuildIds(counter)}")
      .formParam("form_id", "#{formIds(counter)}")
      .formParam("form_token", "#{formTokens(counter)}")
      .formParam("_triggering_element_name", "#{acceptButtons(counter)}")
      .formParam("_triggering_element_value", "Accept")
      .formParam("_drupal_ajax", 1)
      .formParam("ajax_page_state[theme]", "tea")
      .formParam("ajax_page_state[theme_token]", "")
      .formParam("ajax_page_state[libraries]", PAGE_STATE)
      .check(status.is(OK))
      .check(substring("Accepted").exists)
    )
  }

The problem I am facing is that “acceptButtons” is not defined but the debug log shows that there are values.

Strangely, the other variables work well.
The other problem I am facing is with the index; it looks like Gatling’s counter starts from 1, which causes me an issue with first and last elements of the lists like formBuildIds (first element is skipped and last one throws out of bound). I will probably need extra work to decrease the counter by 1 before using but this again throws undefined error. I must be missing something.
Any suggestions?

it looks like Gatling’s counter starts from 1

No, it starts at 0. You can print and verify for yourself.

Oh, thanks for confirming. Then may issue is somewhere else

Hi @klm2002,

Is it “not defined” from the first iteration of your inner loop?
What your debug shows?
How can we reproduce the behavior you experiment?

As you wrote, other variables work well.
The only visible difference is that is a “name” where the other are “value”. Does that change the result type of the variable?

How do you see it is “not defined”?

Cheers!

OK, I worked out and found where my issues were:

  1. Attributes not available turned out to be permission issue - there were pages the user simply had no access. I think the print out were just from previous run so not obvious to spot
  2. The counter is related to the fact that I was using form_build_id and it turned out that there was an additional unrelated form on the page. Using acceptButtons works flawlessly.
    Thanks for looking into this; it certainly helped him do better investigation.
1 Like