Question

Je travaille sur un script de test, testez une interface de repos en gatling à l'aide de Scala.

Pour une ressource de repos spécifique, c'est ce que j'aimerais réaliser:

  1. Obtenez la ressource (qui me donnera des données JSON dans le corps).
  2. Utilisez JSONPATH pour modifier une valeur dans le corps.
  3. Postez le corps modifié à la même URL
  4. J'ai réussi à réussir avec 1 et 3. Le seul problème à gauche consiste à modifier les données JSON qui semblent être au format à la chaîne.

    étapes de test

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

    une partie du scénario

    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
    

    Je reçois les erreurs suivantes

    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
    

Était-ce utile?

La solution

Seulement actuel Gatling 2 Snapshot vous permettra Enregistrer le résultat JSONPATHdans quelque chose d'autre que la chaîne :

jsonPath(expression).ofType[T]

Mais alors, nous n'avons actuellement pas de facilité d'édition, puis de réémaraliser un JSON AST. Nous expédions des analyseurs JSON (Boon et Jackson) afin que vous puissiez probablement réaliser cela vous-même.Vous pouvez également ouvrir une demande de fonctionnalité.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top