Yaroslav Kravchuk
Yaroslav Kravchuk

Reputation: 1

Scala: Get value from list

I am trying to get a random id item from this session array for the payload:

.payload{session => 
  session("ids").as[Array[String]](random.nextInt(
    session("ids").as[Array[String]].length))}

This is not working because I cannot get something from the array once I write .as[Array].

I have to use session object in this way, and when I do anything like the following example, it fails because the code isn't synchronous:


.payload{session => {
  val data = session("ids").as[Array[String]]
  data(random.nextInt(data.length))
}}

How can I get a value from session("ids") in one line, synchronously?

Upvotes: 0

Views: 426

Answers (1)

James Warr
James Warr

Reputation: 2604

If you're using data in a call that's processed as Gatling EL, you can just use#{data.random()}

Upvotes: 1

Related Questions