implement code in a Gatling script

216 views
Skip to first unread message

Magnus Jensen

unread,
Jun 23, 2015, 5:56:54 PM6/23/15
to gat...@googlegroups.com
I have an issue where the client generates an id (no http traffic).
I know that gatling won't execute javascript, but is it possible to programmatically (looking at that javascript code that generates the id) to implant this kind of logic into the script? i.e. using plain java or scala?

Cheers.

Magnus Jensen

unread,
Jun 24, 2015, 5:24:45 AM6/24/15
to gat...@googlegroups.com
Actually to be more specific. I am talking about generating epoch og java.time.now into the gatling script.
Any idea on how to do that "on the fly" within a simulation?

Cheers

Magnus Jensen

unread,
Jun 24, 2015, 5:42:22 AM6/24/15
to gat...@googlegroups.com

Looking at some posts at this forum I guess it could be something like this:

.repeat(40)

 
{

   
Map("timestamp" -> System.currentTimeMillis().toString())

    feed
(csv(
"data/pdaArticle.csv").circular)

 
.exec(http(
"AddArticle")

   
.post(
uri2 + "?ajax_id=GET_ARTICLE_DETAILS&ajax_applid=UI5_RETAIL_ORDER_LABEL&field_id=00055&ajax_value=${art}")

   
.headers(
headers)

   
.formParam(
"""{"WERKS":"${storenumber}","NAME1":"${storename}","LIST_ID":"${timestamp}","TOTAL_LISTS":"${total_lists}","DEVICE_ID":"win8ff38","HEADER_TEXT":"","HASH_BASED_MESSAGE_AUTHENTICAT":"42","ID":"1012371-77-739","REVISION":0,"LABEL_TYPE_LOCKED":false,"LABEL_TYPE":"0"}||{}||{}||{}||[{"ID":0,"NAME":"Standard"},{"ID":23,"NAME":"Etikett (11 x 2) Butikkringen"},{"ID":24,"NAME":"Liten etikett (5 x 3) Butikkringen"},{"ID":41,"NAME":"Prislapp (36 x 17)"},{"ID":51,"NAME":"IS prislapp 48 x 28"},{"ID":61,"NAME":"G etikett 72 x 39"},{"ID":301,"NAME":"Etikett 11 x 2 Plenty"},{"ID":321,"NAME":"Neste Stopp prislapp u.pris"},{"ID":325,"NAME":"Prislapp uten pris (11 x 3)"},{"ID":344,"NAME":"Prislapp (rull 25 x 60)"},{"ID":351,"NAME":"ÖoB medium"}]""", "")

   
.basicAuth(
"${username}","${password}"))

 
}


This is however not working, as in I get the error:

> No attribute named 'timestamp' is defined                  

Andrew Krischer

unread,
Jun 25, 2015, 1:07:23 PM6/25/15
to gat...@googlegroups.com
If you're trying to accomplish getting the current date time, why can't you do just do new Date().getTime, or with Joda DateTime: DateTime.now().getMillis

Then you can save this timestamp whenever you want into the session:

....
.exec(_.set("timestamp", new Date().getTime)) // sets "timestamp" to millis since epoch.

Magnus Jensen

unread,
Jun 25, 2015, 4:09:51 PM6/25/15
to gat...@googlegroups.com
Thank you Andrew,
But the Date (in new Date turns red) what import do I need to do to make this work?

//Magnus

Magnus Jensen

unread,
Jun 25, 2015, 4:25:47 PM6/25/15
to gat...@googlegroups.com
Found it, Java.util.date

Andrew Krischer

unread,
Jun 25, 2015, 4:26:13 PM6/25/15
to gat...@googlegroups.com
The classic java.util.Date: https://docs.oracle.com/javase/6/docs/api/java/util/Date.html

If you can set it up, it's extremely useful to have your IDE resolve imports for you.

Magnus Jensen

unread,
Jun 26, 2015, 1:58:29 AM6/26/15
to gat...@googlegroups.com
I sure did set it up, and if found it for me.

Thanks!
Reply all
Reply to author
Forward
0 new messages