findAll() and saveAs() then iterate over List of elements

Hi guys,

I’m new to Scala + Gatling and I’m struggling to iterate over a list of elements. I’m currently using Gatling 2.2.2

Here is what I’m trying to do:

I’m hitting an URL that returns 3 cookie values in this format (it could return more than 3 too):

["EAF83CB53F707255BA311219D5BC6D6BFD78DA4928F6C237430F4CFAC4CBCCF708CC065B8FAA2F16E467E13A5BB7E476643E8F29A5347B1026D3FB2F4DF0B611983502C8D689AF4393388F33E8A5088A13FDE73E5A89FA5B03097E962F4132D66FD64E0883D9F993B24FF808C70CD452B1B5D818869A5133677882FC6F54B2472769BBBC6A30BA77AC679B9FB38D8549DF6C86F6CACC5CC25EF5ADC8BEBEC2DB1D5B2F39153159BD00ED80802E20152DABB6A82CF54F5F67E59D1EA5F849545A071C31C999320F24BCA683C534B50108C3013CAE","6B8F1B38019FA08B7036879AD66B5EAC3ADBCA825F8C9D80F08B99B50BD5A0E8D9D163C4495CE67606031540C6CFD9275B6B676B22E21407A4F268B7A8945CA46641C9171319EEC57CC0EC2A4947D64A2022FABE872D3D64E4FDC2138E99B115C06FAAFEB6E5ADFB6734BD43CC37507C792D9AACED3B8EEECF66716DF5582715BC30148DCCF745B005603BFA07EB1047D38FD6DF20904A420D4FF1B108F373CB4332ED1B67E7B652378888EF858C4D3104D2573B3C79162032A222F26590E2EA179F91BF5F3EC1135878468F2E1FECBEAE053AFA","EE5B5B2F766B8A1F92870A168E24C50937DEFB6660FF8EAD77D632299B45655431C8F9F0C4EA9CEE1B072363300F15C1DBF67AEF5AD1224434CD5E874F0749D9FB89746EC23FE5D9FF54CEBA7ED57B58B038FC2FD2B14F8B74CF4FE026D4CEEC7B3FDBD6C5596ED0AE812C9F0C16DE20C02C4B3314B05142D834D7F0ED3D18BA69645B48F91CDDE7AAC3FBB94D8815D14CA324B531A74158E1C2F57A4E55F89971F4BAB6869F8C0D6C66809EEA3B3B3BCC8B6FC13015296E93FFA22D768EC6F760C2E65166E4E086C8AED2EB401577B48E9DF8FA"]

I’d like to do a forEach() to iterate over each of these 3 values and use the values to make a request for each of them.

I’m able to save this data using findAll() + saveAs() but I’m struggling to break it into 3 different parts. Basically, when I try to iterate over the elements, I keep getting the whole element instead of just each piece. I did some research and it seems I may have to use map() + mkString() + transform() to convert the data structure above in a simpler format that I can iterate, but not really sure how to do it.

Here is how my code looks like (short version of it):

val scn0 = scenario(“FetchCookies”)

.exec(http(“fetch_cookies”).get(“https://myurl.com/getloadtestcookies”).check(regex(".*").findAll.saveAs(“allCookies”)))

.foreach("${allCookies}", “cookie”) {
exec(session => {
println(“Print ALL cookies below:”)
println(session(“allCookies”))

println(“Print INDIVIDUAL cookie below”)
println(session(“cookie”))

session})
}

This is what I get when I print “all cookies” (3 values, as I was expecting):

SessionAttribute(Session(FetchCookies,1,Map(gatling.http.cache.dns → io.gatling.http.resolver.ShuffleJdkNameResolver@7b00794, allCookies → List([“9D6408E6B62FBBB6134879D40D74D4F06A77B01786A60BDB420F4DC5852E18ADB2ECF777BCD0C22C2D07AB60F5BBDA36E74FA86A5163CEA2288B076F54EC4A611292AC1E0223C11EEDC5ECAE26BAE80702433DF8E446F1CEE3E693689157C102B673BC84692702572249AE4D233C87D95A7370CDC17902B749DE07CAFEBE40BD3103EF33A975D0DED647700C32E2B2BCE4A78AFF66F8D5D1675DC7AFC761E00C739DEF64C942D4926EC27894A69CA500278BBC9AA1A05A9969A4732DB1DD40304E64F39E2BCE029906B0D643EAC0D715D1083610”,“9FA9DD8D7A9B23398B3E96F667EFD7C28A4FDE2F129B2F0BCEED2F8C23DBAE76E210AF77B673A9469584BCE7EDDFD00E554EB0855C7069E26898EE0DA2DDE10D4A27419C71E68AF0575D0331385CEBC5EABB95380F1A79315F95FC7B279E7E155B99B0BF7FC21E16E38DFBB6B973FC7DEFA5AE7112C23CC75ADF1D4D5798939287A1DA8B0ACF0E070FF99939F4277030731534B6C949D12AB02A0362BD7DF10F0635F7C85AA1CF4C2578ED35EC26344C3EC83099BE3D7757016D882BAC1BD8A1881487E98D0DF9E37D535DFB02185C51B79E1F03”,“C4C6B52A751DF9AB13175B48C003C3141363D9CBB2692465FAEAF8D813921643113637BFDEBC1128B58DB4B38F04E82CE655DF50154368E39BBC677BA8DADA88FFBE128DA66BEECA55B1388D2C71F96C2633B0CBD3FD46F85F1720A49D2637F70B4E9AA5CBCE1D2B4082C0E48641BE16D0AADF83E2DBB6D64F96BD43192EA941A0286A9EFCDA4F097B7171B61E31A033A16CCB6C040801D3123CACAF9A18358BC1DE6BE77650781E1F1836CF7D9214851E583F373D7D15C9A097DB2D142BD2C3E15E214E7FE52D9A6E99CE13CD7C1D0081C6F615”], ), ae4372da-0dd1-4032-8489-4141a81cab08 → 0, cookie → [“9D6408E6B62FBBB6134879D40D74D4F06A77B01786A60BDB420F4DC5852E18ADB2ECF777BCD0C22C2D07AB60F5BBDA36E74FA86A5163CEA2288B076F54EC4A611292AC1E0223C11EEDC5ECAE26BAE80702433DF8E446F1CEE3E693689157C102B673BC84692702572249AE4D233C87D95A7370CDC17902B749DE07CAFEBE40BD3103EF33A975D0DED647700C32E2B2BCE4A78AFF66F8D5D1675DC7AFC761E00C739DEF64C942D4926EC27894A69CA500278BBC9AA1A05A9969A4732DB1DD40304E64F39E2BCE029906B0D643EAC0D715D1083610”,“9FA9DD8D7A9B23398B3E96F667EFD7C28A4FDE2F129B2F0BCEED2F8C23DBAE76E210AF77B673A9469584BCE7EDDFD00E554EB0855C7069E26898EE0DA2DDE10D4A27419C71E68AF0575D0331385CEBC5EABB95380F1A79315F95FC7B279E7E155B99B0BF7FC21E16E38DFBB6B973FC7DEFA5AE7112C23CC75ADF1D4D5798939287A1DA8B0ACF0E070FF99939F4277030731534B6C949D12AB02A0362BD7DF10F0635F7C85AA1CF4C2578ED35EC26344C3EC83099BE3D7757016D882BAC1BD8A1881487E98D0DF9E37D535DFB02185C51B79E1F03”,“C4C6B52A751DF9AB13175B48C003C3141363D9CBB2692465FAEAF8D813921643113637BFDEBC1128B58DB4B38F04E82CE655DF50154368E39BBC677BA8DADA88FFBE128DA66BEECA55B1388D2C71F96C2633B0CBD3FD46F85F1720A49D2637F70B4E9AA5CBCE1D2B4082C0E48641BE16D0AADF83E2DBB6D64F96BD43192EA941A0286A9EFCDA4F097B7171B61E31A033A16CCB6C040801D3123CACAF9A18358BC1DE6BE77650781E1F1836CF7D9214851E583F373D7D15C9A097DB2D142BD2C3E15E214E7FE52D9A6E99CE13CD7C1D0081C6F615”]),1478217250338,38,OK,List(ExitOnCompleteLoopBlock(ae4372da-0dd1-4032-8489-4141a81cab08)),),allCookies)

And this is what I get when I print just “individual cookie” (here is the problem, all of them are coming, instead of just 1):

SessionAttribute(Session(FetchCookies,1,Map(gatling.http.cache.dns → io.gatling.http.resolver.ShuffleJdkNameResolver@7b00794, allCookies → List([“9D6408E6B62FBBB6134879D40D74D4F06A77B01786A60BDB420F4DC5852E18ADB2ECF777BCD0C22C2D07AB60F5BBDA36E74FA86A5163CEA2288B076F54EC4A611292AC1E0223C11EEDC5ECAE26BAE80702433DF8E446F1CEE3E693689157C102B673BC84692702572249AE4D233C87D95A7370CDC17902B749DE07CAFEBE40BD3103EF33A975D0DED647700C32E2B2BCE4A78AFF66F8D5D1675DC7AFC761E00C739DEF64C942D4926EC27894A69CA500278BBC9AA1A05A9969A4732DB1DD40304E64F39E2BCE029906B0D643EAC0D715D1083610”,“9FA9DD8D7A9B23398B3E96F667EFD7C28A4FDE2F129B2F0BCEED2F8C23DBAE76E210AF77B673A9469584BCE7EDDFD00E554EB0855C7069E26898EE0DA2DDE10D4A27419C71E68AF0575D0331385CEBC5EABB95380F1A79315F95FC7B279E7E155B99B0BF7FC21E16E38DFBB6B973FC7DEFA5AE7112C23CC75ADF1D4D5798939287A1DA8B0ACF0E070FF99939F4277030731534B6C949D12AB02A0362BD7DF10F0635F7C85AA1CF4C2578ED35EC26344C3EC83099BE3D7757016D882BAC1BD8A1881487E98D0DF9E37D535DFB02185C51B79E1F03”,“C4C6B52A751DF9AB13175B48C003C3141363D9CBB2692465FAEAF8D813921643113637BFDEBC1128B58DB4B38F04E82CE655DF50154368E39BBC677BA8DADA88FFBE128DA66BEECA55B1388D2C71F96C2633B0CBD3FD46F85F1720A49D2637F70B4E9AA5CBCE1D2B4082C0E48641BE16D0AADF83E2DBB6D64F96BD43192EA941A0286A9EFCDA4F097B7171B61E31A033A16CCB6C040801D3123CACAF9A18358BC1DE6BE77650781E1F1836CF7D9214851E583F373D7D15C9A097DB2D142BD2C3E15E214E7FE52D9A6E99CE13CD7C1D0081C6F615”], ), ae4372da-0dd1-4032-8489-4141a81cab08 → 0, cookie → [“9D6408E6B62FBBB6134879D40D74D4F06A77B01786A60BDB420F4DC5852E18ADB2ECF777BCD0C22C2D07AB60F5BBDA36E74FA86A5163CEA2288B076F54EC4A611292AC1E0223C11EEDC5ECAE26BAE80702433DF8E446F1CEE3E693689157C102B673BC84692702572249AE4D233C87D95A7370CDC17902B749DE07CAFEBE40BD3103EF33A975D0DED647700C32E2B2BCE4A78AFF66F8D5D1675DC7AFC761E00C739DEF64C942D4926EC27894A69CA500278BBC9AA1A05A9969A4732DB1DD40304E64F39E2BCE029906B0D643EAC0D715D1083610”,“9FA9DD8D7A9B23398B3E96F667EFD7C28A4FDE2F129B2F0BCEED2F8C23DBAE76E210AF77B673A9469584BCE7EDDFD00E554EB0855C7069E26898EE0DA2DDE10D4A27419C71E68AF0575D0331385CEBC5EABB95380F1A79315F95FC7B279E7E155B99B0BF7FC21E16E38DFBB6B973FC7DEFA5AE7112C23CC75ADF1D4D5798939287A1DA8B0ACF0E070FF99939F4277030731534B6C949D12AB02A0362BD7DF10F0635F7C85AA1CF4C2578ED35EC26344C3EC83099BE3D7757016D882BAC1BD8A1881487E98D0DF9E37D535DFB02185C51B79E1F03”,“C4C6B52A751DF9AB13175B48C003C3141363D9CBB2692465FAEAF8D813921643113637BFDEBC1128B58DB4B38F04E82CE655DF50154368E39BBC677BA8DADA88FFBE128DA66BEECA55B1388D2C71F96C2633B0CBD3FD46F85F1720A49D2637F70B4E9AA5CBCE1D2B4082C0E48641BE16D0AADF83E2DBB6D64F96BD43192EA941A0286A9EFCDA4F097B7171B61E31A033A16CCB6C040801D3123CACAF9A18358BC1DE6BE77650781E1F1836CF7D9214851E583F373D7D15C9A097DB2D142BD2C3E15E214E7FE52D9A6E99CE13CD7C1D0081C6F615”]),1478217250338,38,OK,List(ExitOnCompleteLoopBlock(ae4372da-0dd1-4032-8489-4141a81cab08)),),cookie)

Any ideas/solutions on how to fix it?

Thanks a lot!

Rodrigo

check(regex(".*").findAll.saveAs(“allCookies”))

This regex is too broad. Its not telling the check to capture those three cookies separately.