Hi All,
I am using the doIfEqualsOrElse
condition for one of my script and its not working.I tried to see many help details but still not able to fix my issue.
First of all i am slightly confused as per the Gatling ref its mentioned as like - ```
doIfEqualsOrElse("#{actual}", “expectedValue”) but most of the forum mentioned doIfEqualsOrElse("${actual}", “expectedValue”).difference of “#” and “$”.
when i tried to use the condition wit “#” its checking the condition but always going into Else case of the condition and not sure why.Please find code sample.any help is appreciated.
.check(
status.is(200).saveAs(“namepagestatus”))
doIfEqualsOrElse("""#{session(“namepagestatus”).as[String]}""",200) {
exec(session => {
println(“in condi”)
session
})
.pause(4)
.exec(CreateUser.submitDOB)
.pause(4)
.exec(CreateUser.SessionCheck)
} {
exec(session => {
//println("Enter Name page is failed : " + session("namepagestatus").as[String])
println("else case part")
session
})
}
Thanks
Santosh
difference of “#” and “$”.
- Gatling Expression Language with
${}
was conflicting with Kotlin and Scala String interpolations. As a result, it’s now deprecated and we recommend you now use #{}
instead.
doIfEqualsOrElse(“”“#{session(“namepagestatus”).as[String]}”“”,200) {
Everything is wrong here:
- you’re mixing Gatling Expression Language and Session API. It doesn’t make any sense.
- you’re trying to compare a String and an Int so the result can only be false. Compare values of the same type.
Just do:
doIfEqualsOrElse("""#{namepagestatus}""",200)
Thanks for reply.
I tried with doIfEqualsOrElse("""#{namepagestatus}""",200) but noticed when i print the value of “${namepagestatus}” its not giving anything,but when i print with session(“namepagestatus”).as[String] ,its giving me 200.so i tried to put session(“namepagestatus”).as[String]
please help
I have the feeling you’re pocking around based on some partial knowledge from unofficial and possibly obsolete sources.
If so, I recommend you check the documentation for:
Gatling EL only works when passed to Gatling DSL methods, not in arbitrary code.
Thanks for the update.Let me go through it