Aram
February 20, 2015, 2:36pm
1
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:
* the chain to be executed if the condition is satisfied
* @return
* a new builder with a conditional execution added to its actions
*/
def doIf(condition: Expression[Boolean])(thenNext: ChainBuilder): B = doIf(condition, thenNext, None)
private def equalityCondition(actual: Expression[Any], expected: Expression[Any]): Expression[Boolean] =
(session: Session) =>
for {
expected <- expected(session)
actual <- actual(session)
} yield expected == actual
/**
* Method used to add a conditional execution in the scenario
*
* @param actual
* the real value
* @param expected
* the expected value
* @param thenNext
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
Aram
February 24, 2015, 9:30am
3
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:
Aram
February 24, 2015, 9:48am
5
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
Aram
February 24, 2015, 9:57am
6
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.
Aram
February 24, 2015, 11:22am
8
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