如何在Gatling中将会话变量从一个对象传递到另一个对象? [英] How to pass a session variable from one object to another in Gatling?
本文介绍了如何在Gatling中将会话变量从一个对象传递到另一个对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在ObjectA中提取会话变量,并希望将其传递给ObjectB,实现此目标的最佳方法是什么?
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.
答案:正如Stephane建议通过Session一样,效果很好:
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
}
}
推荐答案
您必须将GroupName存储在exec(function)的用户会话中,以便稍后进行获取(Gatling EL或function).
You have to store GroupName in the user's session in your exec(function) so you can later fetch it (Gatling EL or function).
这篇关于如何在Gatling中将会话变量从一个对象传递到另一个对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文