# saveAs("var")

**URL:** <https://community.gatling.io/t/saveas-var/77>\
**Category:** Gatling (Open-Source)\
**Created:** [May 8, 2012, 12:39am UTC](https://community.gatling.io/t/saveas-var/77 "2012-05-08T00:39:32Z")\
**Posts on this page:** 5\
**Page:** 2

<div class="post-metadata">

**Author:** ![Excilys](https://avatars.discourse-cdn.com/v4/letter/e/8797f3/32.png) [@Excilys](https://community.gatling.io/u/Excilys)\
**Post date:** [August 12, 2012, 11:39am UTC](https://community.gatling.io/t/saveas-var/77/21 "2012-08-12T11:39:28Z")

</div>

Hello Remi,

Lowering the root level to DEBUG will only print the HTTP requests and responses, not the Session content.  
Maybe we should add some DEBUG and TRACE logs to help debugging.

Until then, you can debug your Simulation with a Session function:  
[https://github.com/excilys/gatling/wiki/Session#wiki-functions](https://github.com/excilys/gatling/wiki/Session#wiki-functions)

Regarding your wanting to select a random entry among a check result, you have to:

1. ensure you capture ALL the results of your regex, not only the first one (which is the default): use findAll: [https://github.com/excilys/gatling/wiki/Checks#wiki-extracting](https://github.com/excilys/gatling/wiki/Checks#wiki-extracting)
2. use a transform step in your check in order to save only one of the results: [https://github.com/excilys/gatling/wiki/Checks#wiki-transforming](https://github.com/excilys/gatling/wiki/Checks#wiki-transforming)  
So, you’ll have something like this:

val randomData = new org.apache.commons.math3.random.RandomDataImpl

val selectRandomElementInList = (list: List[String]) =\> {  
val randomIndex = randomData.nextInt(0, list.size - 1)  
list(randomIndex)  
}

…  
…  
check(regex(“XXXXXX”).findAll.transform(selectRandomElementInList).saveAs(“idnr”))

And voila, you can use ${idnr}.

Cheers,

Stéphane

2012/8/12 Remi \<[reemstestcentre@gmail.com](mailto:reemstestcentre@gmail.com)\>

---

<div class="post-metadata">

**Author:** ![Remi](https://avatars.discourse-cdn.com/v4/letter/r/ed8c4c/32.png) [@Remi](https://community.gatling.io/u/Remi)\
**Post date:** [August 12, 2012, 6:49pm UTC](https://community.gatling.io/t/saveas-var/77/22 "2012-08-12T18:49:09Z")

</div>

Hello Stephane,

thanks for your reply.  
unfortunately i am getting an error:

Collecting simulations…  
Exception in thread “main” java.lang.RuntimeException: Compilation failed:  
C:\projecten\tools\gatlin\gatling-charts-highcharts-1.2.5\user-files\simulations\Simulation1.scala:54: error: type mismatch;  
found : List[String] =\> String  
required: Seq[String] =\> ?  
.check(regex("""\<a href="/video/([^"]\*)""").findAll.transform(selectRandomElementInList).saveAs(“idnr”))  
^  
one error found

do you know what’s going wrong?

at com.excilys.ebi.gatling.app.Gatling$$anonfun$compile$1.apply(Gatling.scala:182)  
at com.excilys.ebi.gatling.app.Gatling$$anonfun$compile$1.apply(Gatling.scala:172)  
at com.excilys.ebi.gatling.core.util.IOHelper$.use(IOHelper.scala:24)  
at com.excilys.ebi.gatling.app.Gatling.compile(Gatling.scala:172)  
at com.excilys.ebi.gatling.app.Gatling.start(Gatling.scala:103)  
at com.excilys.ebi.gatling.app.Gatling$.main(Gatling.scala:69)  
at com.excilys.ebi.gatling.app.Gatling.main(Gatling.scala)  
Press any key to continue . . .

---

<div class="post-metadata">

**Author:** ![Excilys](https://avatars.discourse-cdn.com/v4/letter/e/8797f3/32.png) [@Excilys](https://community.gatling.io/u/Excilys)\
**Post date:** [August 12, 2012, 7:16pm UTC](https://community.gatling.io/t/saveas-var/77/23 "2012-08-12T19:16:34Z")

</div>

My fault.  
As the compiler states, findAll returns a Seq[String], not a List[String].  
You just have to change the selectRandomElementInList signature:

val selectRandomElementInList = (list: Seq[String]) =\> {

val randomIndex = randomData.nextInt(0, list.size - 1)

list(randomIndex)

}

Cheers,

Steph

2012/8/12 Remi \<[reemstestcentre@gmail.com](mailto:reemstestcentre@gmail.com)\>

---

<div class="post-metadata">

**Author:** ![Remi](https://avatars.discourse-cdn.com/v4/letter/r/ed8c4c/32.png) [@Remi](https://community.gatling.io/u/Remi)\
**Post date:** [August 12, 2012, 9:28pm UTC](https://community.gatling.io/t/saveas-var/77/24 "2012-08-12T21:28:51Z")

</div>

It looks like it works.

thanks a lot!  
i will check it in the morning again.

---

<div class="post-metadata">

**Author:** ![Sathiyamoorthy\_G\_N](https://avatars.discourse-cdn.com/v4/letter/s/8baadc/32.png) [@Sathiyamoorthy\_G\_N](https://community.gatling.io/u/Sathiyamoorthy_G_N)\
**Post date:** [November 9, 2017, 10:21am UTC](https://community.gatling.io/t/saveas-var/77/25 "2017-11-09T10:21:01Z")

</div>

Can you please help…?  
I used below code.

check(bodyString.saveAs(“BODY”))

how can i print BODY in console window or how can i verify the value that stored in BODY?

Thanks & Regards,  
Sathya

[Previous page](https://community.gatling.io/t/saveas-var/77.md?page=1)
