如何在没有占位符的情况下更改空手道 DSL 中文本响应的所有外观?
How can you change all appearances of a text response in Karate DSL without having a placeholder?
我想知道是否可以在没有占位符的情况下更改空手道 DSL 文本的 Json 响应中出现的所有文本。例如,片断“https://thisisthepart.tochange”在空手道dsl的json响应中多次出现。我不能用“设置”来做,因为我不知道哪个键会出现那个文本。
"imageUrl": ["https://thisisthepart.tochange/idontwannachange/thispart"]
提前致谢
是的,转换为字符串,使用Java API String.replace()
并重新转换:
* string response = response
* json response = response.replace('foo', 'bar')
另请参阅:https://github.com/intuit/karate#type-conversion
编辑:请注意,您可以使用循环“重新构建”JSON:
* def before = { a: 'hello', b: 'world' }
* def after = {}
* def fun = function(k, v){ after[k] = v + 'edit' }
* karate.forEach(before, fun)
* match after == { a: 'helloedit', b: 'worldedit' }
我想知道是否可以在没有占位符的情况下更改空手道 DSL 文本的 Json 响应中出现的所有文本。例如,片断“https://thisisthepart.tochange”在空手道dsl的json响应中多次出现。我不能用“设置”来做,因为我不知道哪个键会出现那个文本。
"imageUrl": ["https://thisisthepart.tochange/idontwannachange/thispart"]
提前致谢
是的,转换为字符串,使用Java API String.replace()
并重新转换:
* string response = response
* json response = response.replace('foo', 'bar')
另请参阅:https://github.com/intuit/karate#type-conversion
编辑:请注意,您可以使用循环“重新构建”JSON:
* def before = { a: 'hello', b: 'world' }
* def after = {}
* def fun = function(k, v){ after[k] = v + 'edit' }
* karate.forEach(before, fun)
* match after == { a: 'helloedit', b: 'worldedit' }