JSON Second check

Hello,

I have function that

object Current {
def extractor =
repeat(2) {
exec(http(“Current”)
.get("/website")
.check(jsonPath("$.product[0]).saveAs(“firstProduct”))
.check(jsonPath("$.product[1]").optional.saveAs(“secondProduct”))
.asJSON
.check(status.is(200)))
}
.exitHereIfFailed
}

Then I have another function

object Transfer {
def request =
doIf("${secondProduct}", “${secondProduct}”) {
exec(http(“Transfer”)
.get("/transfer")
.check(status.is(200)))
}
}

I can only transfer products and get a valid get (200) on my GET request if the user has two different products.
Yet for some strange reason the second function never evaluates to true.
I also do not see the optional ever saving in the session.

Does anyone have any idea?

  doIf("${secondProduct}", "${secondProduct}")

This is what you're calling:
https://github.com/gatling/gatling/blob/master/gatling-core/src/main/scala/io/gatling/core/structure/ConditionalStatements.scala#L40

As you can see, the condition evaluates to true is the resolved expression
for the first member equals the second member (which is a String).

I guess what you want is:

doIf { session
  firstProduct <- session("firstProduct").validate[String]
  secondProduct <- session("secondProduct").validate[String]
} yield firstProduct != secondProduct

That is exeactly what I mean but I keep getting this error.

Code

object Transfer {
def request =

doIf { session
firstProduct ← session(“firstProduct”).validate[String]
secondProduct ← session(“secondProduct”).validate[String]
} yield firstProduct != secondProduct

.exec(http(“Transfer”)
.get("/transfer")
.check(status.is(200)))
}
}

10:23:18.303 [main][ERROR][ZincCompiler.scala:111] i.g.a.ZincCompiler$ - : ‘;’ expected but ‘<-’ found.
10:23:18.305 [main][ERROR][ZincCompiler.scala:111] i.g.a.ZincCompiler$ - definitionId ← session(“firstProduct”).validate[String]
10:23:18.305 [main][ERROR][ZincCompiler.scala:111] i.g.a.ZincCompiler$ - ^
10:23:18.306 [main][ERROR][ZincCompiler.scala:111] i.g.a.ZincCompiler$ - : ';’ expected but ‘<-’ found.
10:23:18.306 [main][ERROR][ZincCompiler.scala:111] i.g.a.ZincCompiler$ - secondProduct**<- session(“secondProduct”).validate[String]**
10:23:18.306 [main][ERROR][ZincCompiler.scala:111] i.g.a.ZincCompiler$ - ^
10:23:18.346 [main][ERROR][ZincCompiler.scala:111] i.g.a.ZincCompiler$ - two errors found

In pseudo code
doIf(${firstProduct} !== ${secondProduct}) {}
Is what I want to do.

Tnx

Some lines disappeared when I pasted:

10:23:18.303 [main][ERROR][ZincCompiler.scala:111] i.g.a.ZincCompiler$ - : ‘;’ expected but ‘<-’ found.
10:23:18.305 [main][ERROR][ZincCompiler.scala:111] i.g.a.ZincCompiler$ - firstProduct**<- session(“firstProduct”).validate[String]**
10:23:18.305 [main][ERROR][ZincCompiler.scala:111] i.g.a.ZincCompiler$ - ^
10:23:18.306 [main][ERROR][ZincCompiler.scala:111] i.g.a.ZincCompiler$ - : ';’ expected but ‘<-’ found.
10:23:18.306 [main][ERROR][ZincCompiler.scala:111] i.g.a.ZincCompiler$ - secondProduct**<- session(“secondProduct”).validate[String]**
10:23:18.306 [main][ERROR][ZincCompiler.scala:111] i.g.a.ZincCompiler$ - ^
10:23:18.346 [main][ERROR][ZincCompiler.scala:111] i.g.a.ZincCompiler$ - two errors found

Sorry

Thank Stephane,

I do still get this:

missing arguments for method doIf in trait ConditionalStatements;
follow this method with `_’ if you want to treat it as a partially applied function
10:54:54.134 [main][ERROR][ZincCompiler.scala:111] i.g.a.ZincCompiler$ - doIf { session =>
10:54:54.135 [main][ERROR][ZincCompiler.scala:111] i.g.a.ZincCompiler$ -

two cents…?

I just provided the condition part of the doIf. You still have to declare the block content.

Do you mean that I have to declare it within the conditional block or call it separately?

Like this

object Transfer {
def request =

doIf { session =>
for {

firstProduct ← session(“firstProduct”).validate[String]
secondProduct ← session(“secondProduct”).validate[String]
} yield firstProduct != secondProduct

}
exec(http(“Transfer”)
.get("/transfer")
.check(status.is(200)))
}
}

Or This

object Transfer {
def request =

def doIf { session =>
for {

firstProduct ← session(“firstProduct”).validate[String]
secondProduct ← session(“secondProduct”).validate[String]
} yield firstProduct != secondProduct

}

doIf(“firstProduct”,“secondProduct”) {
exec(http(“Transfer”)
.get("/transfer")
.check(status.is(200)))
}
}
}

Tnx

The former, but there’s a missing opening { before the exec