[英]How to inject data from csv file in Gatling?
我在执行 Gatling 场景时遇到问题。 它在 Scala DSL 上,也许有人已经遇到过这个问题?
目标:我们需要在场景中注入数据。 基本上,我们有 - 我们的页面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))
}
那么上面的代码产生了一个空的场景(我认为它不应该编译)。 这是因为feed()
方法不在场景构建器链中使用,而是单独使用。 您需要做的是将所有步骤称为chain 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
我的解决方案
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))
}
这是一个完全有效的解决方案,它基于这篇文章,其中目标 URL 是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))
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.