I need to check if “#{player.exists()}”, but sometimes the player attribute exists in the response, but like empty String “”. So if this is the case, my condition will be set on true and simulation will continue, which is not ok for my case. So my question is, is there any way to check if the player exists and not empty?
The Gatling Expression Language is a handy yet simple thing.
For more complex logic that can only be covered by code, you have to resort to passing a function, eg:
.doWhileDuring(session -> Objects.requireNonNull(session.getString("status")).equals("422"), Duration.ofMinutes(2))
.on(doWhileDuring("#{player.isUndefined()}", Duration.ofMinutes(ONE_MINUTE))
.on(exec(getPlayerRequest).pause(ONE_SECOND))
/* The following request is done only if a player was successfully retrieved */
.doIf(session -> Objects.nonNull(session.getString("player")))
.then(
exec(updatePlayerInformationRequest).pause(1, 3)
/* The variable 'validPlayer' is reset when the player is already registered */
.exec(session -> {
if (Objects.equals(session.getString("status"), "422")) {
return session.remove("player");
} else {
return session;
}
}
)
)
)
so, one case could be that the player is not retrieved in the response at all, so I will repeat the process until the player attribute is returned in the response. Next case is, when the player is returned as an attribute, that attribute ‘player’ can be shown in the response (from the previous request) with some value, or can be shown as an empty String (not null). So I want to proceed to the next request only when the player is returned and the value is not empty String.
I was able to achieve first case with this: “#{player.isUndefined()}”, and now I want to achieve another one with something like this: “#{player.existsAndNotEmpty()}” (I know that method does not exist)