Hi gatling experts,
I’ve been using gatling for a while and now with 3.7 version I’d like to give a try to the new java DSL since I’ve always been struggling a bit with scala syntax.
So I’ve taken a project I did with gatling and I’ve tried to convert to use java DSL. I’m still in the process and testing if everything works as expected. Up to now I found a major difference in the checks using findAll function. Here’s an example of such a check in Scala:
def selectProductCode(): HttpCheck = {
css(“input[name=‘productCodePost’]”, “value”).findAll.transform(random).optional.saveAs(“productCode”)
}
and the custom random function was this one:
val random = (list: Seq[String]) => {
list(Random.nextInt(list.size))
}
and here how I translated them in java DSL
public static final CheckBuilder.Final selectProductCode() {
return css(“input[name=‘productCodePost’]”, “value”).findAll().transform(random).optional().saveAs(“productCode”);
}
and the random function became:
private static Function<List, String> random = (final List list) → list.get(ThreadLocalRandom.current().nextInt(list.size()));
Now, I’ve noticed that when the css selector find some occurrences in the html the translated java version works fine as the scala one, but when the css selector find no occurrences of the search then on Scala everything is fine and the only effect is the “productCode” attribute not being stored in the session (as expected), while on java the check breaks with a NPE:
19:44:00.243 [DEBUG] i.g.h.e.r.DefaultStatsProcessor - Request ‘product detail page - pdpTypeAJAX’ failed for user 1: css((input[name=‘productCodePost’],Some(value))).findAll.transform.transformOption.noop extraction crashed: j.l.NullPointerException
I’m not sure if the NPE is happenng in my custom “random” function because I have no check on the list of elements or if the function should not be called at all because there’s no list of elements and in fact the optional call after the transform had the purpose to optionally save the attribute if some value was retrieved.
Has anyone faced something similar with new java DSL?
Thanks
Michele