【问题标题】:Need to pass the arguments from the command line while running gatling.sh in Gatling Performance testing在 Gatling 性能测试中运行 gatling.sh 时需要从命令行传递参数
【发布时间】:2018-01-03 05:43:17
【问题描述】:

我有一个场景,在执行 gatling 时。 sh,我需要从终端传递授权,而不是总是去更改situation.scala文件,因为授权仅针对特定指定,一旦用户注销,我们需要提供新的登录身份验证密钥。基本上我们可以在 Gatling 性能测试中运行 gatling.sh 时从命令行传递参数。请检查simulation.scala 文件以供参考。 ""authorization" -> "运行 gatling.sh 时需要从终端传递值","

import scala.concurrent.duration._

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

class RecordedSimulation extends Simulation {

    val httpProtocol = http
        .baseURL("baseURL")
        .inferHtmlResources()

    val headers_0 = Map(
        "accept" -> "*/*",
        "accept-encoding" -> "gzip, deflate, br",
        "accept-language" -> "en-US,en;q=0.9",
        "access-control-request-headers" -> "access-control-allow-origin,authorization,content-type",
        "access-control-request-method" -> "GET",
        "origin" -> "URL_LINK",
        "user-agent" -> "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.84 Safari/537.36")

    val headers_1 = Map(
        "accept" -> "*/*",
        "accept-encoding" -> "gzip, deflate, br",
        "accept-language" -> "en-US,en;q=0.9",
        "access-control-allow-origin" -> "*",
        **"authorization" -> "Need to pass value from the terminal while running the gatling.sh",**
        "content-type" -> "application/json",
        "origin" -> "ORIGIN_URL",
        "referer" -> "REFERER_URL",
        "user-agent" -> "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.84 Safari/537.36")

【问题讨论】:

  • 感谢您的更新,是的,我看到了文档,但我是性能测试的新手。所以不明白在哪里添加 JAVA_OPTS 值。
  • 你说得对,这没有很好的记录...尝试添加JAVA_OPTS,就像描述的here一样。
  • 再次感谢,我不确定 gatling 中的启动文件。喜欢在 whihc 文件中添加。
  • 启动文件是 gatling.sh 文件,您可以使用您选择的文本编辑器打开和编辑它,或者在调用可执行文件之前指定您的选项。我将创建一个答案以更详细地介绍...

标签: terminal performance-testing gatling gatling-plugin


【解决方案1】:

你的 scala 文件

class abcdClass extends Simulation { val environment = System.getProperty("environment", "Performance Env.") // here "Performance Env." is default value .... .... }

控制台:

适用于 Linux

export JAVA_OPTS="-Denvironment=LoadTest Env"

./gatling.sh

适用于 Windows

设置 JAVA_OPTS="-Denvironment=LoadTest Env"

gatling.bat

【讨论】:

    【解决方案2】:

    根据docs,您可以通过编辑启动脚本 (gatling.sh) 或在命令行中指定它们 之前传递额外的JAVA_OPTS调用启动脚本。

    我建议通过命令行指定它们,因为这看起来更清晰并且明确可见。


    通过命令行指定JAVA_OPTS

    假设您在基于 Unix 的系统上(从您的用户代理猜测您在 OS X 上),您可以在调用 gatling.sh 之前定义额外的JAVA_OPTS,如here 所述:

    JAVA_OPTS="-Dauthorization=foobar" bin/gatling.sh
    

    假设您要访问的值是一个字符串,您应该可以像这样使用附加值:

    "authorization" -> System.getProperty("authorization")
    

    您还可以编辑启动脚本本身。因此,使用您选择的文本编辑器打开 gatling.sh 并在其中添加上述JAVA_OPTS

    【讨论】:

    • 谢谢我明白了:-)
    • 太棒了,请随时 vote upaccept 我的回答
    猜你喜欢
    • 1970-01-01
    • 2018-02-03
    • 1970-01-01
    • 2021-09-30
    • 2017-08-17
    • 2019-07-16
    • 2021-11-25
    • 1970-01-01
    • 2020-07-02
    相关资源
    最近更新 更多