Hi i have this code , i want to exit the loop as soon as i have the match 
def repeatVerif(requestName:String, Duration:Int,LoopDuration:Int,ResMessage:String)=
{
doWhileDuring(session => session.isFailed,LoopDuration.seconds) {
exec(ws("SEND_ACK").sendText("""ACK""")
.await(Duration.milliseconds)(ws.checkTextMessage(requestName).matching(bodyString.is(ResMessage)))) //.onSuccess(session => true)
}
}
1- i want to know can i exit the loop before the duration ends
2- the session.isFailed doesn’t seems to work
thanks is advance
thank you for your replay, i tries this :
def repeatVerif(requestName:String, Duration:Int,LoopDuration:Int,ResMessage:String)=
{
doWhileDuring("!${stop}.exist()}",LoopDuration.seconds,exitASAP = false) {
exec(ws("SEND_ACK").sendText("""ACK""")
.await(Duration.milliseconds)(ws.checkTextMessage(requestName).matching(bodyString.is(ResMessage).saveAs("stop")))) //.onSuccess(session => true)
}
}
it doesn’t seems to work, in the logs i have :
08:40:20.094 [gatling-1-2] DEBUG io.gatling.http.action.ws.fsm.WsPerformingCheckState - Check timeout
08:40:20.100 [gatling-1-2] DEBUG io.gatling.http.action.ws.fsm.WsPerformingCheckState - Check timeout, failing it and performing next action
08:40:20.108 [gatling-1-2] ERROR io.gatling.core.session.LoopBlock$ - Condition evaluation crashed with message ‘No attribute named ‘stop’ is defined’, exiting loop
Please, check the Gatling EL syntax.
I specifically point to "#{foo.isUndefined()}"
for your usage.
same issue:
def repeatVerif(requestName:String, Duration:Int,LoopDuration:Int,ResMessage:String)=
{
doWhileDuring("#{stop.isUndefined()}",LoopDuration.seconds,exitASAP = false) {
exec(ws("SEND_ACK").sendText("""ACK""")
.await(Duration.milliseconds)(ws.checkTextMessage(requestName).matching(bodyString.is(ResMessage).saveAs("stop")))) //.onSuccess(session => true)
}
}
10:29:41.913 [gatling-1-2] DEBUG io.gatling.http.action.ws.fsm.WsPerformingCheckState - Check timeout
10:29:41.913 [gatling-1-2] DEBUG io.gatling.http.action.ws.fsm.WsPerformingCheckState - Check timeout, failing it and performing next action
10:29:41.913 [gatling-1-2] ERROR io.gatling.core.session.LoopBlock$ - Condition evaluation crashed with message ‘Can’t parse ‘#{stop.isUndefined()}’ into boolean’, exiting loop
i think that the problem is with saveAs
From this forum requirements:
Use Up-to-Date Versions
Can’t parse ‘#{stop.isUndefined()}
If a documented feature can’t be parsed on your side, what could the issue possibly be? 
thank you for your replay i add this information:
the issue is with the saveAs command, i have this code which work perfectly i added a saveAs at the end :
.onConnected(exec(ws("sendMessageClientID_Connected").sendText("""{"ClientId":"${randomClientID}","Status":"connected"}""")
.await(7)(ws.checkTextMessage("home_page_Json").matching(bodyString.is(s"${home_page_Json}")saveAs("ssss"))))
exec { session =>
println(session("ssss").as[String])
session
}
on the logs i see the check success :
11:37:13.692 [gatling-1-2] DEBUG io.gatling.http.action.ws.fsm.WsPerformingCheckState - Current check success
11:37:13.692 [gatling-1-2] DEBUG io.gatling.http.action.ws.fsm.WsPerformingCheckState - Check sequences completed successfully
java.util.NoSuchElementException: No attribute named ‘ssss’ is defined
is there any solution to set a variable trru when i have a match
i found out a solution :
def repeatVerif(requestName:String, Duration:Int,LoopDuration:Int,ResMessage:String, partres:String, VariableVerif:String)=
{
asLongAsDuring("${stop"+VariableVerif+".isUndefined()}",LoopDuration.seconds) {
exec(ws("SEND_ACK").sendText("""ACK""")
.await(Duration.milliseconds)(
ws.checkTextMessage(requestName).matching(bodyString.is(ResMessage))
.check(jsonPath("$.method.name").is(partres).saveAs("stop"+VariableVerif))))
}
1 Like