optional do not persist None value

Hi,

During my scenario I need to check the existence of a component in the page (with a regex) to decide what to do just after.

I do it with a regex, an optional variable and a ‘doIf’ :

`
.check(regex("// Google Inc.").optional.saveAs(“testValue”)))
.doIfOrElse(session => session(“testValue”).asOption[String].isDefined) {

`

It work fine when this code is execute for the first time but not when use twice (or in a loop as in may case) without reseting explicitly the variable before saving it ( .exec(session => session.remove(“testValue”) ).

Why the ‘optional’ doesn’t save a None value when the regex doesn’t contain any value ? (bug or misunderstanding ?)
Is there a better way to do that ?

This is a simple code to reproduce that that will produce the output :

`
[GOOD] testValue isEmpty
[GOOD] testValue contain // Google Inc.
[BAD] testValue contain // Google Inc.

`

The code :

`
class RecordedSimulationBug extends Simulation {

val httpProtocol = http
.baseURL(“https://www.google.ch”)
.acceptHeader( “”“text/html,application/xhtml+xml,application/xml;q=0.9,/;q=0.8"”")
.acceptEncodingHeader( “”“gzip, deflate”"")
.acceptLanguageHeader( “”“fr-ch,en-us;q=0.7,en;q=0.3"”")
.connection( “”“keep-alive”"")
.contentTypeHeader( “”“application/x-www-form-urlencoded; charset=UTF-8"”")
.userAgentHeader( “”“Mozilla/5.0 (Windows NT 5.2; rv:31.0) Gecko/20100101 Firefox/31.0"”")

object Search {

val textNotExist =
exec(
http(“HomePage”).get( “”"/""")
.check(status.is(200))
.check(regex(“ZZZ Could not be found In Google Page WQIEOWQIEQOWIE”).optional.saveAs(“testValue”)))
.doIfOrElse(session => session(“testValue”).asOption[String].isDefined) {
exec { session =>
println("[BAD] testValue contain " + session(“testValue”).as[String])
session
}
} {
exec { session =>
println("[GOOD] testValue isEmpty “)
session
}
}
val textExist =
exec(
http(“HomePage”).get( “””/""")
.check(status.is(200))
.check(regex("// Google Inc.").optional.saveAs(“testValue”)))
.doIfOrElse(session => session(“testValue”).asOption[String].isDefined) {
exec { session =>
println("[GOOD] testValue contain " + session(“testValue”).as[String])
session
}
} {
exec { session =>
println("[BAD] testValue isEmpty")
session
}
}

}
setUp(scenario(“Pb Optional”).exec(Search.textNotExist, Search.textExist, Search.textNotExist).inject(rampUsers(1) over 1)).protocols(httpProtocol)
}
`