Conditional checks

567 views
Skip to first unread message

Wayne Izatt

unread,
Aug 28, 2015, 2:22:50 PM8/28/15
to Gatling User Group
Hiya

I have a situation where I might receive a 200 or a 404 in a test. Both are valid, but in the case of the 200, I want to be able to save some parts of the body. Here is what I have currently:

  val getPartial = exec(
    http("GetPartial")
      .get("/user/1/tran/final")
      .header("blah-blah", "${val}")
      .check(status.in(Seq(200, 404)))
      .check(jsonPath("$.pre[?(@.tval == 'some')].url").exisits.saveAs("someUrl"))
      .check(jsonPath("$.pre[?(@.tval == 'all')].url").exists.saveAs("allUrl")))

The problem with the above is that when the return code is 404, I don't want to look for the json data. Is there a way to only do the subsequent checks if the return code is 200?

cheers
Wayne

Abhinav Gogna

unread,
Aug 29, 2015, 11:17:06 AM8/29/15
to Gatling User Group
  val getPartial = exec(
   http("GetPartial")
     .get("/user/1/tran/final")
     .header("blah-blah", "${val}")
     .check(status.in(Seq(200, 404)).saveAs("status"))
     
.doIf("${status}", 404){

Wayne Izatt

unread,
Aug 29, 2015, 1:27:40 PM8/29/15
to Gatling User Group
Thank you! That looks like exactly what I need.

cheers
Wayne

Wayne Izatt

unread,
Aug 31, 2015, 9:07:34 PM8/31/15
to Gatling User Group
So I wrangled with this and no luck. The problem is that doIf() is used at the scenario level, and is not available when we get to looking at the results of a request.

The original problem remains.

cheers
Wayne

John Arrowwood

unread,
Sep 1, 2015, 1:07:45 PM9/1/15
to Gatling User Group
You can make the extract optional, and then it will not complain when the result is a 404.  Sadly, it will also not complain if the result is a 200 but the result was not found.  But then you could use a doIf to inspect that the result is what was inspected, and then error out if it is not.

Alternatively, you can store the status and the full json in a variable, and then do some logic using doif.  However, then you would have to use a different method for parsing and extracting the parts you need from the json.  I've done it.  It's doable.  But it will not be done using basic Gatling DSL.  You can use Jackson or Boon, but you will have to interface to those libraries yourself.  It's not a ton of code, but it is doable.


On Friday, August 28, 2015 at 2:22:50 PM UTC-4, Wayne Izatt wrote:

Stéphane LANDELLE

unread,
Sep 3, 2015, 4:01:18 AM9/3/15
to gat...@googlegroups.com
You have to write your own Check.

Stéphane Landelle
Lead developer


--
You received this message because you are subscribed to the Google Groups "Gatling User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gatling+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages