在Karate DSL中,我如何使用其他数据类型(如int,float,Big等)的替换文本?
问题描述:
我在github上找到了下面的例子。在Karate DSL中,我如何使用其他数据类型(如int,float,Big等)的替换文本?
高清文字= '世界你好再见'
替换文本 |令牌|值| | one | '残酷'| |两个| '好'|
匹配文本==“你好残酷的世界再见”
如果我想更换只能接受整数或其他数据类型的值?例如,
- 替换文字 |令牌|值| |小时| 90 | |价格| 123.45 | |数量| 999999999999 |
我无法将令牌放在另一个文件中,因为json验证器不喜欢没有双引号的<>。有什么建议么?
答
替换是指文本不是JSON,请仔细阅读文档。首先,是与数字和替换没有问题:
* def text = 'hello <name> how many <hours>'
* replace text
| token | value |
| name | 'John' |
| hours | 200 |
* match text == 'hello John how many 200'
现在,如果你试图用JSON乱动,只使用set
关键字。
* def json = { hello: '', hours: null }
* set json
| path | value |
| hello | 'John' |
| hours | 200 |
* match json == { hello: 'John', hours: 200 }
请注意,即使您省略第一行,上述操作也会起作用。另请参阅嵌入式表达式作为在JSON中替换值的另一种方式,请参阅文档。