在 gatling scala 中将值从一个方法传递到另一个方法

问题描述 投票:0回答:1

我正在对E2E场景进行性能测试,有9个请求链。

在这 9 个请求链中,我有两个不同的 baseUrl 集。

请求1:baseUrl1/someUrlPath 请求2:baseUrl2/someUrlPath 请求3:baseUrl1/someUrlPath 请求4:baseUrl1/someUrlPath 请求5:baseUrl1/someUrlPath 请求6:baseUrl2/someUrlPath 。 。 。 请求9:baseUrl1/someUrlPath

每个请求都严重依赖于前一个请求响应的测试数据(无论是响应会话,一些响应值等)

如何在 gatting scala 中实现这个 E2E 用户旅程?

我面临的问题:

  1. 如果我尝试在 gatling scala 中的单个模拟类中构建它,则两个不同的基本 Url 无法使用一个 httpProtocol 进行映射

  2. 如果我构建单独的 httpProtocol,如下所示:

设置( scn.inject(atOnceUsers(1)).protocols(httpProtocol), scn1.inject(atOnceUsers(1)).protocols(httpProtocolSim) ) 那么我无法将值从httpProtocol中使用的方法A传输到链中的另一个方法B httpProtocolSim(作为不同协议中的不同会话)

如果有人有任何策略或解决方法,请告诉我。

performance-testing gatling scala-gatling gatling-plugin
1个回答
0
投票

假设您有一个带有此 json Body 的响应:

{
   "Param1":{
      "ParA": "rand_value"
      }
}

正如 Gatling 的文档所述here,您可以执行检查,然后根据需要提取一个值作为响应,下面是用 Scala 编写的示例代码

    exec(
        http("name")
            .post("your target URL")
            .body(StringBody("""{your body here}"""))
            .check(jsonPath("$.Param1.ParA").saveAs("yourVarNameURL"))
      )

如上面的代码块,已发出请求并进行验证检查并执行提取,因此该值在虚拟用户会话中保存为“yourVarName”(保留

rand_value
)。要了解有关虚拟用户会话的更多信息,请参阅此处

当您成功提取该值,并且想要将其传递到下一个请求时,只需输入:

    exec(
        http("nameRequest")
            .post("#{yourVarNameURL}") //you passed the value rand_value in here
            .body(StringBody("""{your body here}"""))
      )

在此步骤中,您使用 Gattle 的 EL 调用 VU 会话变量

#{yourVarName}
请注意,这与语言的字符串插值
${}
不同,尽管它们具有相同的效果。然后瞧,您成功地将值传递到下一个操作中。

所有这些操作都在一个

.protocols(httpconf)
下,所以当你说
Map
时,我不确定你的代码块到底是什么样的,以进一步提供帮助。

回到你的问题:

If I am trying to build it in a single simulation class in gatling scala, two different base Url can not be mapped with one httpProtocol.

>>> you can have two different base URL with one httpProtocol, as shown in example above and in gatling's document.

希望这有帮助。

© www.soinside.com 2019 - 2024. All rights reserved.