Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/gwt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Scala exitBlockOnFail导致我的脚本失败,并带有“执行失败:未命名属性”_Scala_Gatling - Fatal编程技术网

Scala exitBlockOnFail导致我的脚本失败,并带有“执行失败:未命名属性”

Scala exitBlockOnFail导致我的脚本失败,并带有“执行失败:未命名属性”,scala,gatling,Scala,Gatling,所以我有一个完美的场景,它的定义如下: val basicLoginScenario = createScenario(Config.testName, feeder.random, setSessionParams(PARAM1, Config.param1), setSessionParams(PARAM2, Config.param2), setSessionParams(PARAM3, Config.param3), setSessio

所以我有一个完美的场景,它的定义如下:

 val basicLoginScenario = createScenario(Config.testName, feeder.random,

      setSessionParams(PARAM1, Config.param1),
      setSessionParams(PARAM2, Config.param2),
      setSessionParams(PARAM3, Config.param3),
      setSessionParams(PARAM4, Config.param4),
      exec(RestApi.userLogin))
      exec(RestApi.transaction1))
      exec(RestApi.transaction2)))
但是,当我用exitBlockOnFail包围它时,我得到了以下错误,它似乎发生在发送任何HTTP请求或解析任何请求/响应JSON之前

[GatlingSystem-akka.actor.default-dispatcher-4] ERROR io.gatling.http.action.HttpRequestAction - 'httpRequest-5' failed to execute: No attribute named 'cookie' is defined
这是exitBlockOnFail的代码:

val basicLoginScenario = createScenario(Config.testName, feeder.random,
    exitBlockOnFail{
      setSessionParams(PARAM1, Config.param1)
      setSessionParams(PARAM2, Config.param2)
      setSessionParams(PARAM3, Config.param3)
      setSessionParams(PARAM4, Config.param4)
      exec(RestApi.userLogin))
      exec(RestApi.transaction1))
      exec(RestApi.transaction2))
    })
请注意,cookie参数是从userLogin事务中提取的,在本场景中提取该参数之前,不会在任何地方使用,显然不会在setSessionParam中使用,setSessionParam是:

  def setSessionParams(key: String, value: Any) = {
    exec(_.set(key, value))
  }
以下是userLogin事务:

  val userLogin = {
    exec(http("Login")
      .post("/login")
      .body(ElFileBody("json/Login.json")).asJson
      .check(jsonPath("$.result.cookie").saveAs("cookie")))
  }

我的feeder中没有cookie参数,Login.json中没有分配cookie参数,它只返回cookie参数。正如我在开始时所说的,这个场景工作得非常完美——只有当我使用exitBlockOnFail来处理事务时,问题才会出现。知道是什么原因导致的吗?

您的初始版本有效,因为“exec”可以接受多个exec,而“exitBlockOnFail”可以接受一个链。因此,当您向“exitBlockOnFail”提供多个exec时,只执行最后一个操作

因此,您可以将所有语句包装在“exec”中

exitBlockOnFail{
  exec(
    setSessionParams(PARAM1, Config.param1),
    ...
    exec(RestApi.transaction2)
  )
}
或者把他们锁起来

exitBlockOnFail{
  setSessionParams(PARAM1, Config.param1)
  .setSessionParams(PARAM1, Config.param1)
  .setSessionParams(PARAM2, Config.param2)
  .setSessionParams(PARAM3, Config.param3)
  .setSessionParams(PARAM4, Config.param4)
  .exec(RestApi.userLogin)
  .exec(RestApi.transaction1)
  .exec(RestApi.transaction2)
}

createScenario的定义是什么?我注意到,在您最初的示例中,您使用“,”分隔setSessionParam调用,但您在exitBlockOnFail版本中删除了它。在我的其他问题上,您的帮助下,我最终将不得不开始向您支付:无论如何,以下是定义:def createScenarioname:String,feed:FeederBuilder,chains:ChainBuilder*:ScenarioBuilder={scenarioname.feedfeed.forever{execchains}}我不完全确定setSessionParam为什么需要“,”,但是如果我删除它,我的IDE不喜欢它。不幸的是,我不得不跳入斯卡拉和加特林,没有足够的时间来正确地学习它。。。