Scala 在阅读会话时,如何发出Gatling捕获请求?

Scala 在阅读会话时,如何发出Gatling捕获请求?,scala,gatling,Scala,Gatling,根据,我可以在执行场景时使用会话属性 但是,每次在场景中使用函数文本访问会话时,我都会遇到以下异常: [error] java.lang.UnsupportedOperationException: There were no requests sent during the simulation, reports won't be generated [error] at io.gatling.charts.report.ReportsGenerator$.generateFor(Re

根据,我可以在执行场景时使用会话属性

但是,每次在场景中使用函数文本访问会话时,我都会遇到以下异常:

[error] java.lang.UnsupportedOperationException: There were no requests sent during the simulation, reports won't be generated
[error]     at io.gatling.charts.report.ReportsGenerator$.generateFor(ReportsGenerator.scala:45)
[error]     at io.gatling.app.Gatling.generateReports(Gatling.scala:198)
[error]     at io.gatling.app.Gatling.start(Gatling.scala:82)
[error]     at io.gatling.app.Gatling$.fromArgs(Gatling.scala:59)
[error]     at io.gatling.sbt.GatlingTask.liftedTree1$1(GatlingTask.scala:49)
[error]     at io.gatling.sbt.GatlingTask.execute(GatlingTask.scala:48)
[error]     at sbt.ForkMain$Run$2.call(ForkMain.java:296)
[error]     at sbt.ForkMain$Run$2.call(ForkMain.java:286)
[error]     at java.util.concurrent.FutureTask.run(FutureTask.java:266)
[error]     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
[error]     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
[error]     at java.lang.Thread.run(Thread.java:745)
[error] Simulation FooBarSimulation failed.
[info] Simulation(s) execution ended.
  val scn = scenario("Foobar").feed(feeder).exec { session =>
    http("foo").httpRequest("GET", "http://example.org")
    session
  }.pause(5)
更具体地说,虽然此符号给出了正确的结果:

  val scn = scenario("Foobar").feed(feeder).exec {
    http("foo").httpRequest("GET", "http://example.org")
  }.pause(5)
此操作失败,出现上述例外情况:

[error] java.lang.UnsupportedOperationException: There were no requests sent during the simulation, reports won't be generated
[error]     at io.gatling.charts.report.ReportsGenerator$.generateFor(ReportsGenerator.scala:45)
[error]     at io.gatling.app.Gatling.generateReports(Gatling.scala:198)
[error]     at io.gatling.app.Gatling.start(Gatling.scala:82)
[error]     at io.gatling.app.Gatling$.fromArgs(Gatling.scala:59)
[error]     at io.gatling.sbt.GatlingTask.liftedTree1$1(GatlingTask.scala:49)
[error]     at io.gatling.sbt.GatlingTask.execute(GatlingTask.scala:48)
[error]     at sbt.ForkMain$Run$2.call(ForkMain.java:296)
[error]     at sbt.ForkMain$Run$2.call(ForkMain.java:286)
[error]     at java.util.concurrent.FutureTask.run(FutureTask.java:266)
[error]     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
[error]     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
[error]     at java.lang.Thread.run(Thread.java:745)
[error] Simulation FooBarSimulation failed.
[info] Simulation(s) execution ended.
  val scn = scenario("Foobar").feed(feeder).exec { session =>
    http("foo").httpRequest("GET", "http://example.org")
    session
  }.pause(5)

场景是模拟的计划。因此,当您说
valscn=…
时,您不是在执行模拟,而是在构建一个AST,稍后由gatling执行

所以当你说

val scn = scenario("Foobar").feed(feeder).exec { session =>
  http("foo").httpRequest("GET", "http://example.org")
  session
}.pause(5)
部分
http(“foo”).httpRequest(“GET”http://example.org“”
是一种没有副作用的语句,其值从未使用过。所以它也可能不在那里。就盖特林而言,你的情况是

val scn = scenario("Foobar").feed(feeder).exec { session =>
  session
}.pause(5)
它完全不执行任何操作,因此在生成报告时会产生错误

为了实现您想要的,会话操作必须是一个单独的exec语句。像这样:

val scn = scenario("Foobar").feed(feeder)
  .exec ( session => session.set("foo", "bar") )
  .exec (
    http("foo").httpRequest("GET", "http://example.org")
  )
}.pause(5)

谢谢吕迪格,我正要回答,但你射得更快:)我刚刚推动了一个文档改进。谢谢,非常感谢@StephaneLandelle目前正在使用gatling。我非常喜欢它。在websocket api方面仍有一些困难。见@RüdigerKlaehn谢谢。关于你的WebSocket问题,我在我们的谷歌群上回答了:不可能自动取款机。@RüdigerKlaehn你能看看帖子吗: