more checks questions

Hi:

I found my questions post to this group are always got answered very promptly. Thx for the quick response. Now I have another questions:

I have a scenario that need to send the httprequest first, then parsing the response html: When the html string regex( “”"“content{(\S+)}”"") matchs, it will extract some other substrings StringB from StringA; other wise it will get regex(""“data-object-id=”(\S+)"""") matching from html.

.feed(csv(“messagepool.csv”))
.exec(http("/message")
.get("/message/"+ “${messageID}”)
.check(status.is(200))
.check(regex("""“content{(\S+)}”"").saveAs(“fullJavascriptObj”))
.check(regex(""“data-object-id=”(\S+)"""").saveAs(“objectID”))
.exec((session:Session) => {
doIfOrElse(session.get(“fullJavascriptObj”) != null){
println(session.get(“fullJavascriptObj”))
// then do more string manipulations on fullJavascriptObj
}{
println(session.get(“objectID”))
}

But when I run this, if the response html does hot have regex("""“content{(\S+)}”"") matches, it will fail and won’t go on to extract the next one “objectID”. Is there a way to let it do all the extraction? I am using gatling 2.0

Thx
Shawna

.exec((session:Session) => {
doIfOrElse(session.get(“fullJavascriptObj”) != null){
println(session.get(“fullJavascriptObj”))
// then do more string manipulations on fullJavascriptObj
}{
println(session.get(“objectID”))
}

Is this even compiling ?
You can’t use DSL element inside a .exec() statement as these exec() are made to execute a Scala function.

.exec((session:Session) => {
// I suppose that the type is String … change it if it’s not the case.
val fullJavascriptObj = session.getAttributeAsOptionString
if(fullJavascriptObj.isDefined)){
println(fullJavascriptObj.get)
// then do more string manipulations on fullJavascriptObj
} else {
println(session.get(“objectID”))
}
//It is important that the function returns the new Session, it’s a immutable object.
session
}

cheers
Nicolas

Thx for the response. My main problem is that I need to check more response body after this. Since I can’t use DSL inside of exec, what should I do: the logic is like below:

.exec((session:Session) => {
// I suppose that the type is String … change it if it’s not the case.
val fullJavascriptObj = session.getAttributeAsOptionString
if(fullJavascriptObj.isDefined)){
println(fullJavascriptObj.get)
// then do more string manipulations on fullJavascriptObj

} else {

// i need to get more checks on the response result

Don’t try to go with the builtin regex support, as it doesn’t match your needs.

Have a bodyString check with a transform step where you’ll code whatever complex logic you want:
https://github.com/excilys/gatling/wiki/Checks#wiki-bodyString

https://github.com/excilys/gatling/wiki/Checks#wiki-transforming

Cheers,

Stéphane

Can you add a quick example on how to do that?

like this?

This seems to be not working…
.check(bodyString).saveAs(“bodyString”)

Also if the document can have more examples on how to use the dsl, that would be greate.

Find an example from previous post, seems like this work to get the bodyString saved into a session variable for later processing:

.check(bodyString.transform(string => string).saveAs(“a”))

Not exactly. You sure can store the full body String into the Session, but beware that it might increase the chance it survives micro GC and gets promoted to old, thus increase full GC.
You’d better extract exactly what you want asap with transform.
If you use regex, beware that it performs substring that, until recent JDK updates, keeps a reference to the original char array, so you might have to make a new String(String).