【问题标题】:Passing Multiple Headers in Gatling在 Gatling 中传递多个标题
【发布时间】:2021-08-31 08:17:24
【问题描述】:

我是 Gatling 工具的新手,尝试从另一个文件传递多个标头值,但在编译时遇到错误。

代码:

val header0 = List(Map(
    "Ocp-Apim-Subscription-Key" -> TestParameters.Keyvalue,
    "UserId" -> TestParameters.UserID
  ))

错误:

ingInformation.scala:22:13: type mismatch;
 found   : scala.collection.immutable.Map[String,java.io.Serializable]
 required: Map[String,String]
                        .headers(header0)
                                 ^

【问题讨论】:

    标签: load-testing gatling scala-gatling gatling-plugin maven-gatling-plugin


    【解决方案1】:

    为什么要把header0 做成一个List[Map[String, String]]?

    应该是一个 Map[String, String]:

    val header0 = Map(
      "Ocp-Apim-Subscription-Key" -> TestParameters.Keyvalue,
      "UserId" -> TestParameters.UserID
    )
    

    此外,正如documentation 中所述,标头值必须是字符串。因此,如果TestParameters.KeyvalueTestParameters.UserID 是其他任何东西,例如数字,您必须转换它们,例如使用toString

    【讨论】:

    • found : scala.collection.immutable.Map[String,java.io.Serializable] required: Map[String,String] .headers(header0) ^ 仍然面临同样的错误
    • @SriramRAJASEKARAN 你的钥匙类型有问题。查看密钥类型 - 有 java.io.Serializable 但应该有 String
    • 我已经更新了我的答案。是的,标头值必须是字符串。我猜你是在混合字符串和数字。
    猜你喜欢
    • 1970-01-01
    • 2020-04-28
    • 2016-08-20
    • 1970-01-01
    • 1970-01-01
    • 2014-07-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多