Using variable in function call

69 views
Skip to first unread message

lukas lang

unread,
Jun 24, 2015, 7:06:23 AM6/24/15
to gat...@googlegroups.com
Hi all,
i have a problem when i want to call function with variables from session as parameters:
.check(regex("""data-page="(\d)\.2" data-question""").findAll.saveAs("list1"))
.check(regex("""data-page="(\d)\.2" data-question""").count.saveAs("count1"))

which found (2, 5).

Then i have this function "spustanie" which calls another function "footer"

def spustanie(var_list:List[String],var_count:Int)={
for (i <- 0 to var_count-1) {
var lst2 = var_list(i).toString
var re2 = lst2
if (i == var_count-1) re2
else{
re2 = (lst2.toInt + 1).toString
}
footer (lst2+",2",re2)
}
}


I have tried something like
.exec(session => {
spustanie(session("list1").as[List[String]],session("count1").as[Int])
session
})

which just doesnt seem to work.

Thanks in advance for any help. :)

lukas lang

unread,
Jun 24, 2015, 7:10:22 AM6/24/15
to gat...@googlegroups.com
Sorry i forgot, im using Gatling 2.1.6

Andrew Krischer

unread,
Jun 25, 2015, 12:56:45 PM6/25/15
to gat...@googlegroups.com
Hm, it's not clear to me what your problem is. What are you expecting to happen and what did happen?

From what I can see, I'm guessing that you mean session("list1").as[List[String]] is not returning a List[String]?
Looking at the documentation, http://gatling.io/docs/2.1.6/http/http_check.html?highlight=findall, findall saves the attribute as a Seq[T], which could be your problem. But please elaborate.

lukas lang

unread,
Jun 25, 2015, 1:03:08 PM6/25/15
to gat...@googlegroups.com
Thanks for response.
My "list1" returns List (2, 5), but when i try to call function like ".exec(spustanie($list1, count1))" it tells me that variable is not defined. :(



Dňa štvrtok, 25. júna 2015 18:56:45 UTC+2 Andrew Krischer napísal(-a):

Stéphane LANDELLE

unread,
Jun 25, 2015, 1:18:40 PM6/25/15
to gat...@googlegroups.com
If you call println(session) just before calling spustanien what do you see?

Stéphane Landelle
Lead developer


--
You received this message because you are subscribed to the Google Groups "Gatling User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gatling+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

lukas lang

unread,
Jun 26, 2015, 1:10:51 AM6/26/15
to gat...@googlegroups.com
I get this:
Session(teotest89,7029719221769583319-0,Map(count1 -> 2, count2 -> 2, list1 -> List(2, 5), list2 -> List(0, 3), Ziak_id -> F000000060, <cookies and stuff> ... ),1435150367172,22,OK,List(),<function1>)

And when i try something like this:
.exec(spustanie(list1,count1))

it gives me "not found: value list1" and "not found: value count1"



Dňa štvrtok, 25. júna 2015 19:18:40 UTC+2 Stéphane Landelle napísal(-a):

Stéphane LANDELLE

unread,
Jun 26, 2015, 1:47:51 AM6/26/15
to gat...@googlegroups.com
Are you sure you're saving and pulling from the SAME virtual user?
Could you post a full gist?

Stéphane Landelle
Lead developer


lukas lang

unread,
Jun 26, 2015, 2:02:09 AM6/26/15
to gat...@googlegroups.com
sure, here it is:
https://gist.github.com/anonymous/5426cbf7446c3fe10bb7

Dňa piatok, 26. júna 2015 7:47:51 UTC+2 Stéphane Landelle napísal(-a):

Stéphane LANDELLE

unread,
Jun 26, 2015, 2:07:08 AM6/26/15
to gat...@googlegroups.com
Sorry, but this doesn't compile:
.exec(spustanie(list1,list2,count1,count2))


Stéphane Landelle
Lead developer


lukas lang

unread,
Jun 26, 2015, 2:09:27 AM6/26/15
to gat...@googlegroups.com
That is the thing. I dont know how to call "spustanie" with value "list1" as parameter, because it says "not found: value list1 " 

Dňa piatok, 26. júna 2015 8:07:08 UTC+2 Stéphane Landelle napísal(-a):

Stéphane LANDELLE

unread,
Jun 26, 2015, 2:20:39 AM6/26/15
to gat...@googlegroups.com
The original way is supposed to work: 

.exec(session => {
spustanie(session("list1").as[List[String]],session("count1").as[Int])
session
 })
Stéphane Landelle
Lead developer


lukas lang

unread,
Jun 26, 2015, 2:37:08 AM6/26/15
to gat...@googlegroups.com
That way its compiled OK, it just doesnt really run that function.

> begin                                                    (OK=1      KO=0     )
> zacat testovanie2                                        (OK=1      KO=0     )
> notify_zacat                                             (OK=1      KO=0     )
> logout                                                   (OK=1      KO=0     )




Dňa piatok, 26. júna 2015 8:20:39 UTC+2 Stéphane Landelle napísal(-a):

Stéphane LANDELLE

unread,
Jun 26, 2015, 2:57:52 AM6/26/15
to gat...@googlegroups.com
Now I get it. A perfect example of "it doesn't work" is not the proper way of reporting an issue.

You can't try to trigger requests from an exec(function).
If you want to have conditional blocks, you have to use the proper DSL components, such as doIf.

Stéphane Landelle
Lead developer


lukas lang

unread,
Jun 29, 2015, 2:40:35 AM6/29/15
to gat...@googlegroups.com
Ah i see.
I changed logic a little, now i can use only "repeat".
Thank for all help :)

Lukas

Dňa piatok, 26. júna 2015 8:57:52 UTC+2 Stéphane Landelle napísal(-a):
Reply all
Reply to author
Forward
0 new messages