saveAs("var")

Hi,

Is there a way to use a variable that was captured with RegEx and
saved using saveAs?
Here is my module:
object GetInfo {
    val scnOne = scenario("Get Book Size and Id")

          .exec(
      http("book info")
        .get("/books/custom")
        .check(status.is(200))
        .check(
          regex("""/custom/stylecatalog(.+)=USER_CUSTOM""")
          .findAll
          .saveAs("bookSelectionUrl"))
      )
}

There are multiple matches and they are being saved as List values
into variable bookSelectionUrl.
How can I print this values out? Or how can I choose one of them?
What I need, I need to be able to select 4th selection?

Thank You,
David

Gosh, how could we not document this?

Here is the doc, thanks for reporting:

https://github.com/excilys/gatling/wiki/Session#wiki-el

Cheers,

Steph

2012/5/8 David T <dtishkoff@gmail.com>

That helps!
Thank You!

Hello David,

i tried several attempts to make it work, i have a similar problem.

can you post your complete code? with the explanation of the document

thanks,
Remi

You can also post a gist of what you’re trying to do and we can help you fix it.

2012/8/2 Remi <reemstestcentre@gmail.com>

ok here is my post:

.exec(
http(“randomPage”)
.get("/zoek/dossier?offset="+ test2)
.check(regex(""“a href=”/video/(.*)">Video""")
.findAll
.saveAs(“idnr”))
)

i now want to readout idnr. this should contain multiple values, because the regex matches multiple times.
according to the explanation, this should be a session. but i cannot read it out or display it via println.
hopefully you can help me.

The easiest way is to use some ELs:
https://github.com/excilys/gatling/wiki/Session#wiki-el

for example, you can write:
.exec(
http(“foo”).get(“bar${idnr(0)}baz”)
)

you can even use Session functions:
https://github.com/excilys/gatling/wiki/Session#wiki-functions

.exec((session: Session) =>
println(session.getAttribute(“idnr”))
)

Cheers,

Stéphane

2012/8/3 Remi <reemstestcentre@gmail.com>

I don’t get it, how can i use it now in my code?

how do i store the outcome of my regex in a variable?

i used in my code .saveAs(“idnr”)

Yep, you’ve used saveAs(“idnr”), which means that you’ve saved the outcome of your regex (in your case, a List[String] as you used findAll) into the Session as an attribute named “idnr”.

You can then retrieve this attribute either with an EL inside a String parameter, or programmatically with a Session function.

Do you understand now?

Steph

2012/8/3 Remi <reemstestcentre@gmail.com>

Not related but I don’t think your regex will work, here is my suggestion :
.check(regex(""“a href=”/video/([^"]*)">Video""")

i am not very familiar with gatlin (yet). don’t know what EL stands for.
maybe you can help me by writing the solution for my problem.

i now have:

.exec(
http(“randomPage”)
.get("/zoek/dossier?offset="+ test2 + “&sorteerVolgorde=relevantie&trefwoord=leraar”)
.check(regex(""“a href=”/video/(.*)">Video""")
.findAll
.saveAs(“idnr”))
)

and then there must be something like:

.exec((session: Session) =>
println(session.getAttribute(“idnr”))
)

but this doesnt work

EL means Expression Language. Gatling EL syntax is very similar to the Java one.

Could you explain what you mean by “it doesn’t work”, please? Do you get an exception? Except this EL problem, does your simulation work fine?
Could you post a Github gist with your whole Simulation?

Steph

2012/8/3 Remi <reemstestcentre@gmail.com>

check pastebin:

http://pastebin.com/fzkAbnWX

there is the complete code

simulation works fine except this EL problem.

this is the error

C:\Projecten\testtools\gatling-charts-highcharts-1.2.5\user-files\simulations\Simulation.scala:84: error: not found: value session
.exec((session: Session)
^
one error found

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)
Druk op een toets om door te gaan. . .

My fault, here is the correct Session function:

.exec((session: Session) => {

println(session.getAttribute(“idnr”))

session

})

2012/8/3 Remi <reemstestcentre@gmail.com>

it’s still not working.

do u know how i can print the result of a http request?

Have a look at the logback.xml file (located in the conf directory).

You can lower to root level to DEBUG.

Cheers,

Stéphane

2012/8/6 Remi <reemstestcentre@gmail.com>

Hello Stéphane,

lowering the root level to DEBUG doesn’t print the value of the session attribute idnr
actually my regex works, only problem it’s retrieving the first match.

to make the performance test more realistic i want it to return a random match.

so i am using this session attribute idnr now as ${idnr} in a getrequest

but when i use it like ${idnr[3]}
it gives an error back.

what am i doing wrong?

information below is not complete correct. i now see that my session attribute is printed.

but now it’s printing the first match. how can i make that random?