【问题标题】:Is there a way to randomize the jsonPath array number in get[] myJson?有没有办法随机化 get[] myJson 中的 jsonPath 数组编号?
【发布时间】:2019-08-01 12:53:33
【问题描述】:

我有一个值列表,可用于我的 json 请求中的标题字段。我想在 common.feature 文件中存储一个函数,该函数在执行场景时随机化标题值。

我尝试使用自述文件中常用实用程序选项卡上提供的随机数功能。我已经成功生成了一个随机数,下一步将在 jsonpath 行中使用该随机生成的数字,以便从我的 json 数据列表中检索一个值。


    * def myJson =
"""
{
  "title" : {
               "type" : "string",
               "enum" : [
                  "MR",
                  "MRS",
                  "MS",
                  "MISS"
                  [...]
               ]
            }
}
"""

    * def randomNumber = random(3)
    * def title = get[0] myJson.title.enum


    * print title```

The code above works but I would like to randomize the number within the get[0]. How is this possible in Karate?

【问题讨论】:

    标签: json karate


    【解决方案1】:

    我不确定你想要什么,但你不能在get[randomNumber] myJson.title.enum 中将 0 替换为 randomNumber 吗?

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-03-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-01-28
    • 1970-01-01
    • 2020-09-08
    • 2022-01-22
    相关资源
    最近更新 更多