scala - 如何在 Ga特林 中从 csv 文件注入(inject)数据?

标签 scala scalatest gatling scala-gatling

我在执行加特林场景时遇到问题。它在 Scala DSL 上,也许有人已经遇到这个问题了?

目标:我们需要在场景中注入(inject)数据。 基本上,我们有 - 我们的页面 http://ourPage.com/ 就像所有相对 URL 的根 - CSV 文件中的 URL 列表,这些 URL 基本上是来 self 们 Oracle 数据库的 650000 个 id,组合起来(root+Urls)将模拟我们选择的用户数量。

如何在 Ga特林中从 CSV 文件注入(inject)数据?

包含该文件存在于正确的目录(数据)中并且其中包含正确的数据

希望我的信息能够被理解 我将不胜感激任何形式的帮助

Log:

18:42:54.456 [ERROR] i.g.c.ZincCompiler$ - C:\Users\nikol\OneDrive\Desktop\gatling-charts-highcharts-bundle-2.3.1\user-files\simulations\computerdatabase\BasicSimulation.scala:37: not found: value Article_ID
18:42:54.458 [ERROR] i.g.c.ZincCompiler$ -   feed(csv(Article_ID.csv))
18:42:54.459 [ERROR] i.g.c.ZincCompiler$ -            ^
18:42:54.584 [ERROR] i.g.c.ZincCompiler$ - C:\Users\nikol\OneDrive\Desktop\gatling-charts-highcharts-bundle-2.3.1\user-files\simulations\computerdatabase\BasicSimulation.scala:40: not found: value Article_ID
18:42:54.584 [ERROR] i.g.c.ZincCompiler$ -       .get(s"${Article_ID}") // changet value from Article_ID.csv to Article_ID
18:42:54.584 [ERROR] i.g.c.ZincCompiler$ -                ^
18:42:54.635 [ERROR] i.g.c.ZincCompiler$ - two errors found
18:42:54.639 [ERROR] i.g.c.ZincCompiler$ - Compilation crashed


package computerdatabase

import io.gatling.core.Predef._
import io.gatling.http.Predef._

import scala.concurrent.duration._
import io.gatling.jdbc.Predef._

class BasicSimulation extends Simulation {

  val httpConf = http
    .baseURL("http://my_link.com") // Here is the root for all relative URLs and this is example, this is not real link;
    .acceptHeader("text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8") // Here are the common headers
    .doNotTrackHeader("1")
    .acceptLanguageHeader("en-US,en;q=0.5")
    .acceptEncodingHeader("gzip, deflate")
    .userAgentHeader("Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:16.0) Gecko/20100101 Firefox/16.0")

  val headers_10 = Map("Content-Type" -> "application/x-www-form-urlencoded") // Note the headers specific to a given request
  val scn = scenario("Scenario Name") // A scenario is a chain of requests and pauses

  feed(csv(Article_ID.csv))

    .exec(http("Request")
      .get(s"${Article_ID}") // changet value from Article_ID.csv to Article_ID
    .pause(7))

  setUp(scn.inject(atOnceUsers(1)).protocols(httpConf))
}

最佳答案

上面的代码会产生一个空的场景(我认为它不应该编译)。这是因为 feed() 方法不是在场景构建器链中使用,而是单独使用。您需要做的就是将所有步骤称为 chain fe:

val scn = scenario("Scenario Name")
  .feed(csv(Article_ID.csv))
  .exec(http("Request"))
    .get(s"${Article_ID}")
  .pause(7))

如果这不是问题,而您只是粘贴了有错误的代码,则检查 CSV 文件的格式是否正确。 CSV 的第一行应包含属性名称(我知道人们经常忘记它)例如:

Article_ID, OtherColumn, AnotherColumn
1, Test, Lorem Ipsum
2, Abc, Dolor Sit Amet
3, Xyz, Consectetur Adipiscing

关于scala - 如何在 Ga特林 中从 csv 文件注入(inject)数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52139077/

相关文章:

scala - 使用特定于版本的 scala 编译器选项

scala - 如何使用intellij运行多模块sbt的所有scalatest?

Scala + Eclipse + WebServer = 一个网络应用

scala - Akka 上下文观察/取消观察发生在关系之前

scala - java.lang.IncompatibleClassChangeError:使用ScalaCheck和ScalaTest实现类

scala - Scala Koans 中的 ===(三等号)运算符是什么?

scala - 在三引号字符串中使用 gatling session 变量

json - 如何在加特林的Json Body中添加随机值?

Scala Actor : receive vs react