Gatling:RESTリソースを入手、JSON Leafの変更、投稿後
質問
テストスクリプトで作業しているため、Scalaを使用してGatlingのRESTインタフェースをテストしています。
特定のRESTリソースの場合、これは私が達成したいものです:
- 本体の「JSONデータを教えてください)のリソースを取得します。
- jsonPathを使用して、ボディの値を変更します。
- 修正したボディを同じURLに戻します
私は1と3で成功することができました。唯一の問題は、文字列形式であるように見えるJSONデータを変更することです。
テストステップ
object WebTestCollection {
def getAccountDetails() = http("Get account")
.get("/account")
.check(jsonPath("$.billingAccount").saveAs("accountjson"))
def postNewAccountDetails() = http("Post modified account")
.post("/account").asJSON
.body("${accountjson}")
}
.
シナリオの一部
val scn = scenario("Web Usage")
.feed(testRuns)
.exec(WebTestCollection.getAccountDetails())
.exitHereIfFailed
.exec(session => {
var account = session.getAttribute("accountjson")
account.notes = "Performance Test Comment"
println(account)
session.setAttribute("accountjson", account)
}
)
.exec(WebTestCollection.postNewAccountDetails())
.exitHereIfFailed
.
次のエラーを取得します
09:59:30.267 [ERROR] c.e.e.g.a.ZincCompiler$ - <snip>/WebScenario.scala:172: value notes is not a member of Any
09:59:30.268 [ERROR] c.e.e.g.a.ZincCompiler$ - account.notes = "Performance Test Comment"
09:59:30.269 [ERROR] c.e.e.g.a.ZincCompiler$ - ^
09:59:30.664 [ERROR] c.e.e.g.a.ZincCompiler$ - one error found
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at scala_maven_executions.MainHelper.runMain(MainHelper.java:164)
at scala_maven_executions.MainWithArgsInFile.main(MainWithArgsInFile.java:26)
Caused by: Compilation failed
at sbt.compiler.AnalyzingCompiler.call(AnalyzingCompiler.scala:76)
at sbt.compiler.AnalyzingCompiler.compile(AnalyzingCompiler.scala:35)
at sbt.compiler.AnalyzingCompiler.compile(AnalyzingCompiler.scala:29)
at sbt.compiler.AggressiveCompile$$anonfun$4$$anonfun$compileScala$1$1.apply$mcV$sp(AggressiveCompile.scala:71)
at sbt.compiler.AggressiveCompile$$anonfun$4$$anonfun$compileScala$1$1.apply(AggressiveCompile.scala:71)
at sbt.compiler.AggressiveCompile$$anonfun$4$$anonfun$compileScala$1$1.apply(AggressiveCompile.scala:71)
at sbt.compiler.AggressiveCompile.sbt$compiler$AggressiveCompile$$timed(AggressiveCompile.scala:101)
at sbt.compiler.AggressiveCompile$$anonfun$4.compileScala$1(AggressiveCompile.scala:70)
at sbt.compiler.AggressiveCompile$$anonfun$4.apply(AggressiveCompile.scala:88)
at sbt.compiler.AggressiveCompile$$anonfun$4.apply(AggressiveCompile.scala:60)
at sbt.inc.IncrementalCompile$$anonfun$doCompile$1.apply(Compile.scala:24)
at sbt.inc.IncrementalCompile$$anonfun$doCompile$1.apply(Compile.scala:22)
at sbt.inc.Incremental$.cycle(Incremental.scala:52)
at sbt.inc.Incremental$.compile(Incremental.scala:29)
at sbt.inc.IncrementalCompile$.apply(Compile.scala:20)
at sbt.compiler.AggressiveCompile.compile2(AggressiveCompile.scala:96)
at sbt.compiler.AggressiveCompile.compile1(AggressiveCompile.scala:44)
at com.typesafe.zinc.Compiler.compile(Compiler.scala:158)
at com.typesafe.zinc.Compiler.compile(Compiler.scala:142)
at com.excilys.ebi.gatling.app.ZincCompiler$.apply(ZincCompiler.scala:104)
at com.excilys.ebi.gatling.app.SimulationClassLoader$.fromSourcesDirectory(SimulationClassLoader.scala:34)
at com.excilys.ebi.gatling.app.Gatling$$anonfun$12.apply(Gatling.scala:89)
at com.excilys.ebi.gatling.app.Gatling$$anonfun$12.apply(Gatling.scala:89)
at scala.Option.getOrElse(Option.scala:108)
at com.excilys.ebi.gatling.app.Gatling.start(Gatling.scala:89)
at com.excilys.ebi.gatling.app.Gatling$.fromMap(Gatling.scala:54)
at com.excilys.ebi.gatling.app.Gatling$.runGatling(Gatling.scala:74)
at com.excilys.ebi.gatling.app.Gatling$.main(Gatling.scala:49)
at com.excilys.ebi.gatling.app.Gatling.main(Gatling.scala)
... 6 more
.解決
現在のGatling 2スナップショットを聴除させてください JSONPathの結果を保存する文字列以外の何かに:
jsonPath(expression).ofType[T]
.
しかし、それでは現在編集のための施設を持っていません、そして次にJSON ASTを再シリアル化します。 私たちはJSONパーサー(ブーンとジャクソン)を出荷して、おそらくこれを自分で達成することができます。機能要求を開くこともできます。
所属していません StackOverflow