0

我有一个场景,在执行加特林时。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")
4

2 回答 2

0

你的 Scala 文件

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

安慰:

对于 Linux

导出 JAVA_OPTS="-Denvironment=LoadTest 环境"

./gatling.sh

对于 Windows

设置 JAVA_OPTS="-Denvironment=LoadTest 环境"

加特林.bat

于 2018-01-05T10:07:01.740 回答
0

根据文档,您可以通过JAVA_OPTS编辑启动脚本(gatling.sh)或在调用启动脚本之前在命令行中指定它们来传递附加信息。

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


JAVA_OPTS通过命令行指定:

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

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

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

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

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

于 2018-01-04T19:22:26.243 回答