如何在Gatling中将会话变量从一个对象传递到另一个对象?

时间:2015-12-01 10:14:19

标签: scala performance-testing gatling

我在ObjectA中提取会话变量并希望将其传递给ObjectB,实现此目的的最佳方法是什么?

object ObjectA {
  val foo = exec(jsfPost("Request1", "/something.xhtml")
        .formParam("SUBMIT", "1")
        .check(regex("""Count:([^:]*),""").saveAs("Count"))
        )
       .pause(1)
       .exec { session =>  
          val Count = session("Count").as[String].toInt
          val GroupName = SomeCustomFunc(Count)
        }
        .exec(ObjectB.bar)
}

object ObjectB{      
  val bar = group(GroupName){
      myChain
  }
}

非常肯定在看到答案后我会感到愚蠢,但到目前为止还没有成功实现这一点。

答案:正如Stephane建议通过会议工作正常:

object ObjectA {
  val foo = exec(jsfPost("Request1", "/something.xhtml")
        .formParam("SUBMIT", "1")
        .check(regex("""Count:([^:]*),""").saveAs("Count"))
        )
       .pause(1)
       .exec(session => session.set("GroupName", SomeCustomFunc(session("Count").as[String].toInt)))
       .exec(ObjectB.bar)
}

object ObjectB{      
  val bar = group("${GroupName}"){
      myChain
  }
}

1 个答案:

答案 0 :(得分:2)

你必须在你的exec(函数)的用户会话中存储GroupName,以便以后可以获取它(Gatling EL或函数)。