每次运行代码时,我都需要从下面的示例json中选择任何随机值。我如何在空手道中实现这一目标?我需要获取任何随机值并在另一个功能文件中使用。
def myJson =
"""
{
"sampleJson": {
"random1": "1",
"random2": "2",
"random3": "3",
"random4": "4",
"random5": "5"
}
}
"""
答案 0 :(得分:2)
另请参阅:https://github.com/intuit/karate#commonly-needed-utilities
* def random = function(max){ return Math.floor(Math.random() * max) + 1 }
* def myJson =
"""
{
"sampleJson": {
"random1": "1",
"random2": "2",
"random3": "3",
"random4": "4",
"random5": "5"
}
}
"""
* def key = 'random' + random(5)
* def result = myJson.sampleJson[key]
* print result