json - 有没有办法随机化 get[] myJson 中的 jsonPath 数组编号?
问题描述
我有一个值列表,可用于我的 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?
解决方案
我不确定你想要什么,但你不能用 randomNumber 替换 0get[randomNumber] myJson.title.enum
吗?
推荐阅读
- php - 使用 phpmyadmin 的数据库在网站上搜索
- python - 从子类调用父方法的正确方法
- r - R SelectizeInput - ChoiceValues ChoiceNames 的类似解决方案?
- javascript - 在在线报告中选择“所有筛选器”时,Power BI SDK 不获取或设置筛选器
- php - Laravel Hash::check() 使用不同的盐和前缀
- c++ - 在 C++ 中为错误处理声明局部方法变量是否会带来内存或性能成本?
- apache-spark - Pyspark - 希望创建双列的规范化版本
- apache-kafka - 如何在 kafka 控制台生产者中添加键序列化器和值序列化器
- node.js - Github Actions 部署 docker 打包 | 错误:未找到:python
- python - 删除数据框中的“Specials Unicode”