How to pass a session variable from one object to another in Gatling?

巧了我就是萌 提交于 2019-12-12 08:57:52

问题


I'm extracting session variable in ObjectA and would like to pass it to ObjectB, what is the best way to achieve this?

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
  }
}

Pretty sure I'll feel stupid after seeing the answer, but so far did not managed to get this working.

Answer: As Stephane suggested passing through Session worked fine:

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:


You have to store GroupName in the user's session in your exec(function) so you can later fetch it (Gatling EL or function).



来源:https://stackoverflow.com/questions/34017785/how-to-pass-a-session-variable-from-one-object-to-another-in-gatling

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!