【问题标题】:How to inject data from csv file in Gatling?如何在 Gatling 中从 csv 文件中注入数据?
【发布时间】:2019-02-07 21:08:21
【问题描述】:

我对 Gatling 场景的实施有疑问。它在 Scala DSL 上,也许有人已经遇到过这个问题?

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

如何在 Gatling 中从 CSV 文件中注入数据?

包括该文件存在于正确的目录(数据)中,并且在里面有正确的数据

希望我的信息可以理解 我将不胜感激任何形式的帮助

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

【问题讨论】:

    标签: scala scalatest gatling scala-gatling


    【解决方案1】:

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

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

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

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

    【讨论】:

    • 谢谢,我今天为自己找到了我的问题的解决方案,你的项目的时间框架有能力创造奇迹)))。它看起来和你的很相似。
    【解决方案2】:

    我的解决方案

       object Article {
            val feeder = csv("search.csv").random // randomly id from the csv file
    
            val search = feed(feeder)
              .exec(http("unike_Article") // execute your request 
                .get("/article/88.8888/${searchCriterion}") 
              )
              .pause(2)
      }
    
      val users = scenario("Users").exec(Article.search)
    
      setUp(users.inject(rampUsersPerSec(2)to(20)during(3 minutes)).protocols(httpConf))
    
    }
    

    【讨论】:

      【解决方案3】:

      这是一个完全有效的解决方案,它基于this post,其中目标网址是http://localhost:8080/cat?name=XYZ,猫的名字来自一个带有name 列的CSV 文件:

      import java.util.concurrent.TimeUnit
      import io.gatling.core.Predef.{Simulation, scenario, _}
      import io.gatling.http.Predef.{http, status}
      import scala.concurrent.duration.FiniteDuration
      
      class MySimulation extends Simulation{
      
      val baseURL = "http://localhost:8080"
      val httpConf = http.baseUrl(baseURL)
      val csvFeeder = csv("cats.csv").random
      
      val scn = scenario("my cats")
          .feed(csvFeeder)
          .exec(http("my cats")
          .get(baseURL + "/cat")
          .queryParam("name", "${name}"))
      
      setUp(
          scn.inject(
          constantUsersPerSec(100) during (FiniteDuration(10,TimeUnit.SECONDS)),
          )
          .protocols(httpConf))
      }
      

      【讨论】:

        猜你喜欢
        • 2014-03-09
        • 2017-10-14
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2022-01-21
        • 2020-03-24
        • 2021-02-02
        • 1970-01-01
        相关资源
        最近更新 更多