首页 > 解决方案 > Gatling 如何将捕获的动态值替换为列表

问题描述

在 gatling 中,我使用以下检查功能从请求中提取 propertyid 列表。

            .get(uri21 + "/search/address/q=20+ABC+Street&qt=address&view=property&newSearch=true&searchWindowId=")
            .check(regex("""propertyKey="(.*?)"""").findAll.saveAs("propertyid")))
            .exec(session => {
                println(session("propertyid").as[String])
                session
            })
            

我将以下属性 ID 捕获到列表中。

List(44772164, 44772175, 44772176, 44772177, 44772196, 44772197, 44772198, 44772212, 44772213, 44772214, 44772226, 44772227, 44772228, 44772247, 44772248, 44772249, 44772260, 44772261, 44772262, 44772276)

我需要在以下请求中以逗号分隔格式格式化和替换这些值(如下面的请求)。根据地址的不同,propertyid 的数量将不同..可以有 1 个或多个,请您指导我如何完成。

.exec(http("/torchlist") .get(uri21 + "/torchlist/status.json?property_id=44772164, 44772175, 44772176, 44772177, 44772196, 44772197, 44772198, 44772212, 44772213, 44772214, 44772226, 44772227, 44772228 , 44772247, 44772248, 44772249, 44772260, 44772261, 44772262, 44772276&_=1627273897640&search_type_param=address"))

标签: listscalagatling

解决方案


transform在您的支票中使用,请参阅https://gatling.io/docs/gatling/reference/current/http/check/#transforming

.get(uri21 + "/search/address/q=20+ABC+Street&qt=address&view=property&newSearch=true&searchWindowId=")
  .check(
    regex("""propertyKey="(.*?)"""")
      .findAll
      .transform(listOfIds => listOfIds.mkString(","))
      .saveAs("concatenatedIds")
  )
)

推荐阅读